0%

python如何用csv包读取和写入csv

读取

1
2
3
4
5
6
7
8
import csv

file_path = '1908194624.csv'
with open(file_path,encoding="utf_8") as f:
reader = csv.reader(f)
header_row = next(reader) #略过标题行
for row in reader: #遍历每一行
weibo_id = row[1]

写入

1
2
3
with open('result_file.csv','w') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(header)