Multiple pandas.dataframe to one csv file

后端 未结 2 1321
庸人自扰
庸人自扰 2020-12-29 17:16

I have multiple pandas dataframes, and hope to write them as one CSV file. What is the most straightforward way?

For example, from following four dataframes,

2条回答
  •  北海茫月
    2020-12-29 17:40

    For anyone that needs to append multiple dataframes to same csv vertically, you can use this:

    for df in list_of_dfs:
        with open('all_dfs.csv','a') as f:
            df.to_csv(f)
            f.write("\n")
    

提交回复
热议问题