import csv # 如果不添加newline=""的话,就会每条数据中间都会有空格行
with open("test.csv","w", newline="") as csvfile:
# 初始化写入对象
writer = csv.writer(csvfile) #先写入columns_name
#writer.writerow(["index","a_name","b_name"])
#写入多行用writerows
writer.writerows([[0,1,2],[1,2,3],[2,3,4]])
得到结果: