Python 3.x 将列表中的数据添加到已有数据的csv列
我是Python新手,因此我想问: 我有一个csv,有两列a和B A. B 1. 种皮 2. 测试BPython 3.x 将列表中的数据添加到已有数据的csv列,python-3.x,csv,Python 3.x,Csv,我是Python新手,因此我想问: 我有一个csv,有两列a和B A. B 1. 种皮 2. 测试B 您可以使用csv库进行同样的操作。请参阅下文: # Importing library import csv # data to be written row-wise in csv file data = [[3, 'testd'], [4, 'teste'], [5, 'testf'], [6, 'testg']] # opening the csv file in 'a+
您可以使用csv库进行同样的操作。请参阅下文:
# Importing library
import csv
# data to be written row-wise in csv file
data = [[3, 'testd'], [4, 'teste'], [5, 'testf'], [6, 'testg']]
# opening the csv file in 'a+' mode
file = open(filename, 'a+', newline ='')
# writing the data into the file
with file:
write = csv.writer(file)
write.writerows(data)
我明白了,它起作用了。非常感谢你!