• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Groupby two columns on on two axis

Resolved: Groupby two columns on on two axis

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’d like to groupby pandas dataframe on two different columns on two different axes, however, struggling to figure it out Sample code:
so far I have the following solution, I cannot use .resample because then I loose all the names:
Sample output:

Answer:

You can use df.pivot to get this (I have added in a group by following from comments saying pivot causes an error), using the below:
However this will output with Date as the column names, rather than ‘numbers’ as in your question:
(Note: not an exact match the the output in the question due to the random data in the df in the question).
To correct this, you can just set all the columns to be ‘numbers’ using the below:

If you have better answer, please add a comment about this, thank you!

pandas python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: how to get and read an xml file in a zip file using xml.etree

02/04/2023

Resolved: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed. cors error not resolving

02/04/2023

Resolved: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘crm.email’ doesn’t exist (Connection: mysql, SQL: select count(*) as aggregate from `email`

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.