# -*- coding: utf-8 -*-
#如何把python的处理结果导出到文件中呢?
#1. 导出文本文件
#语法:to_csv(filePath,sep=',',index=True,header=True)
#index:是否导出行索引,默认为True(虽然一般不需要)
#header:是否导出列名,默认为True
from pandas import DataFrame
df = DataFrame(data={
"age":[21,22,23],
"name":["zhangsan","lisi","wangwu"]
},index=['first','second','third'])
#自动导出行索引
df.to_csv("D:/python/workspace/pythonStudy/exportdata.csv")
#不导出行索引
df.to_csv("D:/python/workspace/pythonStudy/exportdata.csv",index=False)
#通过以上两句,可以发现,文件会发生覆盖,而不是追加写
#这里仅仅以导出csv文件为例,当然也是可以导出为其他格式的文件的