调整列的顺序,代码:
df = pd.read_excel(r'./14.xlsx')
df_fitting = df[df['fitting_data']==1]
df_prediction = df[df['fitting_data']==0]
a_mean = df_fitting['A'].mean()
df_prediction['predictions_A'] = a_mean
df_prediction.eval('ws = predictions_A * B/1000',inplace=True)
df_prediction["B_2010-1"] = df_prediction['B'].cumsum(axis=0)
df_prediction["C_2010-1"] = df_prediction['ws'].cumsum(axis=0)
df_new = pd.DataFrame(df_prediction,columns=['1','2','3','4','5','predictions_A',
'B','B_2010-1',
'ws','C_2010-1'])
df_new.to_excel(r'./file/14.xlsx',index = False)
print('done!')
|