公司任务:有五个设备统计53周电器用电数据。现在要拆分到每周每种电器用电数据。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import pandas as pd import os
data1 = pd.read_excel("CRT2_OUTPUT (1).xlsx") gb = data1.groupby('FISCAL_WEEK') for week,df_son in gb: df_son.to_excel(f'{week}.xlsx',index=False)
path = './APS2' dlj = os.listdir(path) for i in dlj: name1='./APS2/'+i data1 = pd.read_excel(name1) name2='./CART2/'+i data2 = pd.read_excel(name2) name3='./FIN2/'+i data3 = pd.read_excel(name3) name4='./ODT2/'+i data4 = pd.read_excel(name4) name5='./PRE2/'+i data5 = pd.read_excel(name5) datanew = pd.concat([data1,data2,data3,data4,data5], axis=0) datanew.to_excel(f'{i}',index=False)
path = './MERGE' dlj = os.listdir(path) for i in dlj: name1='./MERGE/'+i data1 = pd.read_excel(name1) datanew = data1.groupby(['PART_NUM'])['OUTPUT'].sum() datanew.to_excel(f'{i}')
path = 'G:/桌面/e/type2/MERGE_SUM/' dlj = os.listdir(path) datanew = pd.read_excel('2.xlsx') for i in dlj: name1 = path+i data1 = pd.read_excel(name1) datanew = pd.merge(datanew, data1, how='outer', on=['PART_NUM']) datanew.to_excel('a.xlsx',index=False)
|