StopIteration error when creating a dataframe from a dictionary

  csv, dataframe, dictionary, python

So I have created a dataframe from a dictionary to perform a time series exercise. When I create the dataframe (I’m doing this in Google Colab) the cell runs correctly. but when I do full_df.head(). I get StopIteration error. Does anyone know why this happens?

This is what I have:

df = pd.read_csv('all_stocks_5yr.csv', usecols=["close", "Name"])

gp = df.groupby("Name")
my_dict = {} 
for record in gp: 
    if record[0] in my_dict:
       my_dict[record[0]].append(record)
    else:
       my_dict[record[0]] = [record]

full_df = pd.DataFrame.from_dict(my_dict, orient='index')

full_df.head() #This is where I get the error.

Source: Python Questions

LEAVE A COMMENT