python中读写csv文件的方法

1.利用csv包

import csv

#写
f=open("file.csv",'w',encoding='utf-8')
writer=csv.writer(f)
writer.writerows(" ")
f.close()

#读
f=open("file.csv",'r',encoding='utf-8')
reader = csv.reader(f)
f.close()

2.利用pandas

import pandas as pd
#写
dataframe.to_csv("file.csv",index=False)
#读
data = pd.read_csv("file.csv")

index表示是否写入dataframe中的index(行名),默认为True

猜你喜欢

转载自blog.csdn.net/sigmeta/article/details/78252601