I am trying to group and sum-aggregate a specific column in my dataframe and then write this entire output to excel; however, when i check the excel file after using the below code, it only contains the one aggregated column as the output and does not include any of the other grouping. I am someone could help me correct the code or provide suggestions as to how to achieve this? Thanks in advance!
my_df = pd.DataFrame(df.groupby(['Parent Category','Expense'])['Parent Category','Expense','Variance'].sum())
Next, I use the below code to write it to excel but it does not write the output into excel as in the image above
writer = pd.ExcelWriter('Test.xlsx', engine = 'xlsxwriter')
my_df.to_excel(writer,sheet_name = '1', index = False)
writer.save()
why is the group by output not the same when written to excel?