背景:
程序运行中的产生的列表数据,保存成csv表格到本地中。
import csv
import pandas as pd
list = [[1, 2, 3], [4, 5, 6], [7, 9, 9]]
name = ['one', 'two', 'three']
name2 = ['小花', '小明', '小智']
test = pd.DataFrame(columns=name, index=name2, data=list)
print(test)
# 转换csv
test.to_csv('testcsv.csv', encoding='gbk')
# 读取CSV文件--csv库
with open('testcsv.csv','r') as f:
reader = csv.reader(f);
# print(reader)
for row in reader:
print(row)