使用 Pandas python 复制文件并上传到另一个 csv 文件

Copying a file and uploading to another csv file with Pandas python

如何复制一个 csv 文件的所有内容,然后将其全部粘贴到另一个 csv 文件和 pandas 中?该函数将删除file2中的所有内容(如果有),然后从file2中复制并粘贴file1中的所有内容。所以 file1 中的内容应该出现在 file2.

file1 =pd.read_csv(`file1.csv`, low_memory=False)
file2 =pd.read_csv(`file2.csv`, low_memory=False)

file1 内容

Hello how are you?
I am good.
What about you. 

只需在pandas中使用to_csv()方法:-

file1.to_csv('file2.csv',index=False)

您也可以通过文件处理来做到这一点:-

with open('file1.csv','r') as file1:
    with open('file2.csv','w') as file2:
        file2.write(file1.read())