• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Reshape data frame, so the index column values become the columns

Resolved: Reshape data frame, so the index column values become the columns

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

Question:

I want to reshape the data so that the values in the index column become the columns
My Data frame:
Desired Data frame:
enter image description here
Is there an easy way to do this? I also have 9 other categorical variables in my data set in addition to the Gender and Location variables. I have only included two variables to keep the example simple.
Code to create the example dataframe:

Answer:

You can transpose the dataframe and then split and set the new index:
Transpose
Split and set the new index

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

pandas pandas-melt python reshape unpivot
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How do I navigate a table without any easily accessible distinctions?

27/03/2023

Resolved: Can a pod make itself unavailable temporarily in kubernetes?

27/03/2023

Resolved: How to plot logistic probability for custom generalized additive model (GAM) plot?

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

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