python中读写csv文件的方法

来源:互联网 发布:手机赌博软件 编辑:程序博客网 时间:2024/05/11 15:47

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

原创粉丝点击