0

i’ve got a python/pandas groupby that is grouped on name and looks like this:

name    gender      year        city            city total
jane    female      2011        Detroit          1
                    2015        Chicago          1
dan     male        2009        Lexington        1  
bill    male        2001        New York         1
                    2003        Buffalo          1
                    2000        San Francisco    1

and I want it to look like this:

 name   gender  year1   city1     year2 city2    year3  city3   city total
 jane   female  2011    Detroit   2015  Chicago                  2
 dan    male    2009    Lexington                                1  
 bill   male    2000    Chico     2001  NewYork  2003   Buffalo  3

so i want to keep the grouping by name and then order by year and make each name have only one column. it's a variation on a dummy variables maybe? i'm not even sure how to summarize it.

  • https://stackoverflow.com/questions/22127569/opposite-of-melt-in-python-pandas – BBischof Apr 17 '18 at 04:12
  • i still can't figure it out. when i pivot it i get the list of cities and years for each name but then how do i move the first entry of the list to "year 1" and etc? – user7939708 Apr 17 '18 at 04:44

0 Answers0