将列表数据输出存储在csv文件
import csv
import pandas as pd
list1=[1,2]
list2=[3,4]
list=[]
list.append(list1)
list.append(list2)
print(list)
column=['one','two']
test=pd.DataFrame(columns=column,data=list)
test.to_csv('test.csv')
将不同列表(不同DataFrame)数据存储在不同sheet
import csv
import pandas as pd
writer = pd.ExcelWriter('test2.xlsx')
list1=[1,2]
list2=[3,4]
list=[]
list.append(list1)
list.append(list2)
test1=pd.DataFrame(list)
L_list=[]
list3=[5,6]
list4=[7,8]
L_list.append(list3)
L_list.append(list4)
test2=pd.DataFrame(L_list)
test1.to_excel(writer,sheet_name='one',index=False)
test2.to_excel(writer,sheet_name='two',index=False)
writer.save()
writer.close()
将嵌套列表数据存储在不同sheet
import xlwt
import pandas as pd
LL_list=[[1,2],[3,4]]
LL_list1=pd.DataFrame(LL_list[0])
LL_list2=pd.DataFrame(LL_list[1])
with pd.ExcelWriter('test3.xls') as writer:
LL_list1.to_excel(writer, sheet_name='df1')
LL_list2.to_excel(writer, sheet_name='df2')
|