Python如何读写csv数据

Jackey Python 2,211 次浏览 , 没有评论
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 如何读写csv数据
import csv
# 读
rf = open('test.csv', 'r', encoding='gbk')
reader = csv.reader(rf)
print(next(reader))
# for row in reader: print(row)
# 写
wf = open('test_copy.csv', 'w', encoding='gbk')
writer = csv.writer(wf)
for row in reader: writer.writerow(row)
wf.flush()
# 如何读写csv数据 import csv # 读 rf = open('test.csv', 'r', encoding='gbk') reader = csv.reader(rf) print(next(reader)) # for row in reader: print(row) # 写 wf = open('test_copy.csv', 'w', encoding='gbk') writer = csv.writer(wf) for row in reader: writer.writerow(row) wf.flush()
# 如何读写csv数据
import csv

# 读
rf = open('test.csv', 'r', encoding='gbk')
reader = csv.reader(rf)
print(next(reader))

# for row in reader: print(row)

# 写
wf = open('test_copy.csv', 'w', encoding='gbk')
writer = csv.writer(wf)
for row in reader: writer.writerow(row)

wf.flush()

 

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

Go