![db723889ebfb4d021f6065a051f950ec.gif](https://i-blog.csdnimg.cn/blog_migrate/7383e8bbd6ee43c600b8e33b59bd788c.gif)
pandas是python最重要的一个数据分析处理的库包。今天详细介绍以下如何将列表、字典、数组数据结构格式输出到csv文件,便于统计等分析处理。
list_to_csv
import csv import pandas as pd# newline是数据之间不加空行for n in range(10):
f = open('./list_to_csv.csv','a',newline = '')
writer = csv.writer(f)
writer.writerow(name_list)
f.close()name_list = [['zhangsan','12','男','汉'],
['lisi','34','男','回'],
['wangwu','58','女','汉']
]
header = ['姓名','年龄','性别','民族']# encoding='utf_8_sig'防止中文乱码test = pd.DataFrame(columns=header,data=name_list).to_csv('test.csv',encoding='utf_8_sig')
dict_to_csv
import csv import pandas as pdheader = ['姓名','年龄','性别','民族']pd.DataFrame(datas).to_csv('pdict_to_csv.csv',encoding='utf_8_sig')
dict_to_csv
import csv import pandas as pdheader = ['姓名','年龄','性别','民族']pd.DataFrame(datas).to_csv('pdict_to_csv.csv',encoding='utf_8_sig')
array_to_csv
import numpy
a = numpy.array([ [1,2,3], [4,5,6], [7,8,9] ])
numpy.savetxt("test.csv", a, delimiter=",")
pandas 读取数据自学笔记(1)
pandas 数据结构自学笔记(2)
pandas与SQL数据查询(3)
·end·
—如果喜欢,快分享给你的朋友们吧—
我们一起愉快的玩耍吧