0

I have csv files that require sorting. In each one there is a column for 'answer' and next to it a column for the 'date'. Is there some panda code to turn the dates into a header and then organize the answers by dates? For example:

answer  date
0       7/15/16
0       7/15/16
1       7/15/16
1       7/22/16
0       7/22/16
3       7/22/16

to

7/15/16   7/22/16
0         1
0         0
1         3
jeleung2
  • 21
  • 2

1 Answers1

3

Pretty sure that this is a dup:

df['idx'] = df.groupby('date').cumcount()
df.pivot(index='idx', columns='date', values='answer')

gives:

date  7/15/16  7/22/16
idx                   
0           0        1
1           0        0
2           1        3
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74