1

df:

job_Id    Company_Name   Min_Salary 
   1           X              50  
   2           X              12  
   3           X              45  
   1           y              63 
   2           y              75  
   3           y              25   

df_output:

job_Id    X      y
  1      50     63   
  2      12     75 
  3      45     25     

I need to unstack my dataframe as i showed in the above example. I tried unstack func but i am not able to use properly.

James Lin
  • 153
  • 2
  • 10
  • Use [`.pivot`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.pivot.html#pandas-dataframe-pivot) – Andrej Kesely Aug 20 '21 at 08:25

1 Answers1

0

pivot the dataframe, and if needed, reset the index.

>>> df.pivot('job_Id', 'Company_Name', 'Min_Salary').reset_index()

Company_Name  job_Id   X   y
0                  1  50  63
1                  2  12  75
2                  3  45  25
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45
  • Is possible not post dupe answers? I think mainly dupes if are many times repeated and easy find by google. Thanks. – jezrael Aug 20 '21 at 08:58