Sergey  Gulbin Sergey Gulbin - 8 months ago 154
Python Question

How to save a list of dataframes to csv

I have a list of data frames which I reshuffle and then I want to save the output as a csv. To do this I'm trying to append this list to an empty data frame:

l1=[year1, year2,..., year30]
shuffle (l1)
columns=['year', 'day', 'tmin', 'tmax', 'pcp']
df2=pd.DataFrame(columns=columns, index=index)

This result in an empty data frames with a bunch of Nans. I don't necessarily need to append my reshuffled list to a dataframe, I just need to save it as a csv, and this is the only way I find yet.


I think you need concat with to_csv if l1 is list of DataFrames:

print pd.concat(l1).to_csv('filename')