• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: use custom column list in pandas crosstab

Resolved: use custom column list in pandas crosstab

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

Question:

I have a dataframe like as below
I would like to do the below
a) create 4 year columns year_2019,year_2020,year_2021 and year_2022.
b) put the count of records for each ID under the respective year columns
I tried the below
But the problem is it convert all year values as columns in output dataframe.
My real dataframe has 4 million rows and has 50 unique year values.(from 1970 to 2022)
But I want the count of year values only for 2019,2020,2021 and 2022.
I expect my output to be like as below

Answer:

You can use:
output:

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

dataframe pandas-groupby python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How do I use SetWindowText with Unicode in Win32 using PowerShell?

01/04/2023

Resolved: Shopware 400 Status Error “This value is too long. It should have 255 character or less.” When I Try Updating Database Table

01/04/2023

Resolved: Using AWK to count multiple patterns in a file

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

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