0

So my data looks like:

enter image description here

Text version:

    Month   Stream  Profit  Users
0   2021-01 Google  $50,000 8000
1   2021-01 Bing    $5,000  2000
2   2021-02 Google  $50,000 10000
3   2021-02 Bing    $10,000 5000
4   2021-03 Google  $50,000 15000
5   2021-03 Bing    $25,000 10000 

And I am trying to create merged column output with not only month-year merged but also totals of each value monthwise so I want my output to be visualized as something like:

enter image description here

And I am trying to visualize it in a jupyter notebook output. Data would be monthly level so it is possible to visualize it on a jupyter notebook and does not have to be written in an excel file. Because of high volume of data, I, of course, cannot go through each cell and merge in excel, and show anyways. It is also important to show totals next to individual contributions from a readability perspective so I cannot have a separate table grouped by months only and have total. Data is dynamic. There could be more than two streams or less for a particular month. There are 6 columns in actual data and I want to show percentages and totals for each so there will be 3x more numerical columns than the actual number of numerical columns in data. But the number of features is pretty much fixed. I am currently looking at pandas styling and have gone through questions like:

  1. Pandas Data Frame how to merge columns
  2. Merge cells with pandas

But they are group-by-based solutions which are not valid for my case as there could be some cases where the total is equal coincidently for two months and I do not want to combine them. Moreover, the position of totals is really important for me to be next to each percentage contribution so by groupby approach, I would be losing that as well. The solution does not have to be pandas styling based and I am open to any solution as long as it is capable to incorporate streams dynamically, take care of each column and their totals separately and display totals next to each individual column. It even does not have to be a tabular output either but any visualization that can carry similar information with readability would be good enough. Feel free to suggest any approach that I might have missed out on and would be a better way to approach this problem.

Hamza
  • 5,373
  • 3
  • 28
  • 43
  • Have you checked out xlswriter, from what I played with anything you do in excel manually can be done using that library. – Wolfy Jan 19 '22 at 04:55
  • Yes but it needs to be visualized as well. SO formatting stays in a file, however I am trying to visualize in a jupyter notebook. Should have added that in question :D – Hamza Jan 19 '22 at 05:02
  • I think that for analysis, you're better off with with two separate tables (or a single table, and some group-by results). – 9769953 Jan 19 '22 at 05:08
  • Related: https://stackoverflow.com/questions/49533330/pandas-data-frame-how-to-merge-columns – 9769953 Jan 19 '22 at 05:11
  • This is not possible at the level of the dataframe – mozway Jan 19 '22 at 05:57

0 Answers0