list数据的存储
1 存储成csv格式
简单方法:
a = [3,3,4,4] df = {'a': a} df = pd.DataFrame(df) df.to_csv('./a.csv')
复杂方法:
import numpy as np import numpy as np import csv import codecs def data_write_csv(file_name, datas): # file_name为写入CSV文件的路径,datas为要写入数据列表 datas = list(map(lambda x:[x],datas)) file_csv = codecs.open(file_name, 'w+', 'utf-8') writer = csv.writer(file_csv, delimiter=' ', quotechar=' ', quoting=csv.QUOTE_MINIMAL) for data in datas: writer.writerow(data) print("保存文件成功,处理结束") a = [3,3,3,44,4,4335,444,44,44,4,56,6] data_write_csv('./a.csv', a)
2 存储成txt格式