利用pandas讀取和寫入csv
import pandas import datetime import numpy as np df = pandas.read_csv('abc.csv', index_col=0,encoding ='utf-8') dfNew = pandas.read_csv('writeNew.csv', index_col=0,encoding ='utf-8') j = 0 for i in df.iloc: new=pandas.DataFrame({'字段1':i.name, '字段2':'XXXX', '字段3':'XXXX', '字段4':'時間'}, index=[1]) dfNew=dfNew.append(new,ignore_index=True) j=j+1 if (j%10000 == 0): print(j) dfNew.to_csv("test.csv",quoting=1,index=False,sep=',') print('成功')
寫入CSV的時候,用【quoting=1】,寫入CSV的數據會加上雙引號