1
$\begingroup$

I have the following DataFrame and I want it exported in an excel file with different sheets having different words as shown in the image

0   2020-06-14  coronavirus es  -0.021277   coronavirus is  -0.006024
1   2020-06-13  coronavirus es  -0.021277   coronavirus is  0.000000
2   2020-06-12  coronavirus es  -0.021277   coronavirus is  0.000000
3   2020-06-11  coronavirus es  -0.011111   coronavirus is  0.000000
4   2020-06-14  COVID-19 es 0.000000    COVID-19 is 0.000000
5   2020-06-13  COVID-19 es 0.000000    COVID-19 is 0.000000
6   2020-06-12  COVID-19 es 0.000000    COVID-19 is 0.000000
7   2020-06-11  COVID-19 es 0.000000    COVID-19 is 0.000000

I want to be able to export it to different sheets in an excel file in the following format with the 1st sheet being as follows and the next having (COVID-19 es, COVID-19) and so on..

Date        Coronavirus is  coronavirus es                                  
6/11/2020   0              -0.5 
6/12/2020   0.05            0           
6/13/2020   0               -0.5    
6/14/2020   -0.05           -0.66

so far I have tried using pivot wr.pivot_table(columns=['query_x', 'query_y']) but that does not give memy desired result and also trying to export it in different sheets is a bit confusing for me. I have tried the following.

writer = pd.ExcelWriter(path, engine = 'xlsxwriter')
df1.to_excel(writer, sheet_name = 'b')
writer.save()
writer.close()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.