作者:愛妳yi輩zi | 来源:互联网 | 2023-05-17 12:36
python6-1如何读写csv数据readercsv.reader(rf)writercsv.writer(wf)解决方案:使用标准库中的csv模块,可以使用其中read
python 6-1 如何读写csv数据reader=csv.reader(rf)/writer=csv.writer(wf)
解决方案:
使用标准库中的csv模块,可以使用其中reader和writer 完成对csv文件的读写
http://table.finance.yahoo.com/table.csv?s=000001.sz
csv 模块
csv读
rf=open("xx.csv",'rb')
reader=csv.reader(rf)
for row in reader:
print row
reader.next()
csv写
wf=open("xx.csv",'wb')
writer=csv.writer(wf)
writer.writerow(row)
import csv
rf=open("pingan.csv",'rb')
reader=csv.reader(rf)
for raw in reader:
print raw
rf.close()
wf=open("pingan3.csv",'wb')
writer=csv.writer(wf)
#writer.writerow(['2018-08-08', '29.23988', '29.23988', '29.23988', '29.23988', '000', '0.05398'])
wf.flush()
wf.close()