Reputation: 3
Continuing from the post that I'll link below, the answer provides how to split a data frame into the number of months the df has (i.e if a dataframe has 6 months, then you'll get 6 dataframes, one for each month). What I want to know is a generic code, such as a for loop to save those dataframes as csv files.
Pandas split one dataframe into multiple dataframes
I used the second solution to split my df because it spans more than one year.
Upvotes: 0
Views: 1516
Reputation: 1924
This will grab each df from your dictionary (the value) and save it to a csv who's file name is the key from the dictionary + '.csv'. Is that what you're looking for?
for key, df in df_dict.items():
df.to_csv(key+'.csv')
Upvotes: 1
Reputation: 107
how about this:
for key in dfs.iterkeys():
dfs[key].to_csv("C:/", 'df' + key + '.csv')
Upvotes: 0