• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home » Resolved: Summarise Data using group_by across several columns

Resolved: Summarise Data using group_by across several columns

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

Question:

Let’s say I have a dataframe where all columns are factors:
I want a table that will give a proportion percentage and n across every column a:d by Gender and Region so the end result would look something like this: enter image description here
I’ve done this for a using the code (but I want to do this also for all the other columns b,c,d without replicating the code):
so for a I get this:

Answer:

What you probably first want to do is to transform your data in a tidy-format by using pivot_longer on a:d, and then group also by this variable, from there it is almost the same code as you wrote:
To create your desired output shape, you can do:
Created on 2022-06-16 by the reprex package (v2.0.1)

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

r
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Input Focus between two React Components

02/04/2023

Resolved: linq2db throws exception when filtering by nested collection

02/04/2023

Resolved: Table data is coming as empty in React

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

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