1

Dataframe is setup like so. I want a pivot table with a multi-level index of account, pseudo. I want the columns to be the individual weeks, and the values to be sales. The data is pseudo x week x account so I shouldn't need to aggregate any data. How can I accomplish?

   pseudo        week     account   sales
0   31527  2017-12-30  4430012511    2.79
1  145584  2017-12-16  4430012511    8.37
2   31608  2017-12-23  4430012511   19.53
3    6362  2017-12-16  4430012511    5.58
Lisle
  • 1,620
  • 2
  • 16
  • 22

1 Answers1

6

This is just a simple pivot table, is it not?

df.pivot_table(index=['account', 'pseudo'], columns='week', values='sales')

week               2017-12-16  2017-12-23  2017-12-30
account    pseudo                                    
4430012511 6362          5.58         NaN         NaN
           31527          NaN         NaN        2.79
           31608          NaN       19.53         NaN
           145584        8.37         NaN         NaN
Alexander
  • 105,104
  • 32
  • 201
  • 196
  • There it is! I was thinking my index needed to be a grouping of the two variables and kept receiving errors. – Lisle Jan 17 '18 at 20:56