2

Because when I do

pd.pivot_table(df, values='frequency', columns='word', index=['senator', 'state'])

I get the correct output

[10 rows x 42725 columns]

But when I do

df.pivot(values='frequency', columns='word', index=['senator', 'state'])

I get

ValueError: Wrong number of items passed 118158, placement implies 2

Here is the shape of my data:

        word  frequency  senator state
1   straight          5  daschle    sd
2    screens          1  daschle    sd
3  knockdown          1  daschle    sd
4  Combating          3  daschle    sd
5        say        169  daschle    sd
FooBar
  • 15,724
  • 19
  • 82
  • 171
  • 2
    Have a look at [this](https://nikolaygrozev.wordpress.com/2015/07/01/reshaping-in-pandas-pivot-pivot-table-stack-and-unstack-explained-with-pictures/) page that explain the difference. – Fabio Lamanna Mar 12 '16 at 15:33
  • Possible duplicate of [Pandas: Difference between pivot and pivot\_table. Why is only pivot\_table working?](http://stackoverflow.com/questions/30960338/pandas-difference-between-pivot-and-pivot-table-why-is-only-pivot-table-workin) –  Mar 12 '16 at 15:56

0 Answers0