import pandas as pd
mydata={'consum_amount_rice':[21,21,4,8,7,7,28,42,21,7],
'consum_unit_rice':[1,1,2,1,6,6,5,5,5,6]}
df = pd.DataFrame(data=mydata)
units=[1,2,5,6]
for x in units:
dfx = df[df['consum_unit_rice'] ==x]
我想将多个数据框dfx
导出到多个Excel文件,例如:
file1 = 'G:\python\out\consumption_rice_1.xlsx'
,用于df1
file2 = 'G:\python\out\consumption_rice_2.xlsx'
,代表df2
file5 = 'G:\python\out\consumption_rice_5.xlsx'
,代表df5
file6 = 'G:\python\out\consumption_rice_6.xlsx'
,代表df6
我可以在此循环中使用pd.to_excel
吗?