pandas -调整列的顺序

调整列的顺序,代码:

#test
df = pd.read_excel(r'./14.xlsx')
df_fitting = df[df['fitting_data']==1]#1 true
df_prediction = df[df['fitting_data']==0]#0 false
a_mean = df_fitting['A'].mean()

df_prediction['predictions_A'] = a_mean

#ws = HA
df_prediction.eval('ws = predictions_A * B/1000',inplace=True)

df_prediction["B_2010-1"] = df_prediction['B'].cumsum(axis=0) #by row

df_prediction["C_2010-1"] = df_prediction['ws'].cumsum(axis=0) #by row

#export data 
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!')

你可能感兴趣的:(#,python,python)