How to add pandas data to an existing csv file?

后端 未结 6 1414
离开以前
离开以前 2020-11-22 10:02

I want to know if it is possible to use the pandas to_csv() function to add a dataframe to an existing csv file. The csv file has the same structure as the load

6条回答
  •  不要未来只要你来
    2020-11-22 10:14

    with open(filename, 'a') as f:
        df.to_csv(f, header=f.tell()==0)
    
    • Create file unless exists, otherwise append
    • Add header if file is being created, otherwise skip it

提交回复
热议问题