By using the following code, I have been able to transform my dataframe df
(shown in attached Picture1) into dictionary of subset dataframes (split on basis of rows sharing same Year, Month, Week).
Resultant dictionary is shown in Picture2.
dict_df = dict(tuple(df.groupby(['Year', 'Month', 'Week'])))
print(dict_df)
Next, I am trying to reference elements in Open
column in dict_df
by using the following code and the output is in Photo3:
for item in dict_df.keys():
print(dict_df[item]['Open'])
print(type(dict_df[item]['Open']))
Question:
How do I reference to any item (say, 0th or 1st or any ) within the Open
column in Picture3? I tried print(dict_df[item]['Open'][0])
but I get error get_loc raise KeyError(key) from err KeyError: 0