I merged two dataframes and I export them to excel fileI'd like to reorder merged columns, I tried some solutions but without success
At the moment I get this output:
But my goal is to get this one:
This is my code (just dataframes):
df = df[['home','away','scorehome','scoreaway','result','best_bets','oddtwo','oddthree', 'sum_stats', 'over05', 'over15', 'over25', 'over35', 'over45', 'goal', 'esito', 'tournament', 'uniquefield']] df2 = df2[['home2','away2','htresult','shresult','result2','tournament2', 'uniquefield2']]print(pd.merge(df, df2, left_on='uniquefield', right_on='uniquefield2', how='left').drop('uniquefield2', axis=1))df3 = df.merge(df2, left_on='uniquefield', right_on='uniquefield2', how='left').drop(['uniquefield2', 'tournament2', 'home2', 'away2', 'result2'], axis=1) df3 = df3.sort_values(by=["home","away","scorehome","scoreaway","htresult","shresult","result","best_bets","oddtwo","oddthree", "sum_stats", "over05", "over15", "over25", "over35", "over45", "goal", "esito", "tournament", "uniquefield"])# determining the name of the filefile_name = 'BexDataFull.xlsx'# saving the exceldf3.to_excel(file_name)print('DataFrame is written to Excel File successfully.')
Thanks for your help