Closed
Description
xref #2567
In [27]: data = pd.DataFrame({'hr1': [514, 573], 'hr2': [545, 526],
...: 'team': ['Red Sox', 'Yankees'],
...: 'year1': [2007, 2008], 'year2': [2008, 2008]})
...:
In [28]: data
Out[28]:
hr1 hr2 team year1 year2
0 514 545 Red Sox 2007 2008
1 573 526 Yankees 2008 2008
In [29]: pd.lreshape(data, {'year': ['year1', 'year2'], 'hr': ['hr1', 'hr2']})
Out[29]:
team year hr
0 Red Sox 2007 514
1 Yankees 2008 573
2 Red Sox 2008 545
3 Yankees 2008 526
In [30]: pd.wide_to_long(data, ['hr', 'year'], 'team', 'index')
Out[30]:
hr year
team index
Red Sox 1 514 2007
Yankees 1 573 2008
Red Sox 2 545 2008
Yankees 2 526 2008
So we should drop one of these.