I am relatively new to python programming. I have a list of pandas dataframes that all have the column 'Year'. I am trying to group by that column and convert to a dictionary where the dictionary key is the variable 'Year' and values is a list of dataframes of that year. Is this possible in python?
I tried this:
grouped_dict = list_of_csv_files.groupby(by = 'Year').to_dict()
I believe I will have to loop through each dataframe? I did not provide any data because I am hoping it is a somewhat simple solution.
I also tried this:
grouped_dict = list_of_csv_files.groupby(by = 'Year').apply(lambda dfg: dfg.to_dict(orient='list')).to_dict()
Any guidance would be greatly appreciated!