On Pandas documentation of the pivot method, we have:
Examples -------- >>> df foo bar baz 0 one A 1. 1 one B 2. 2 one C 3. 3 two A 4. 4 two B 5. 5 two C 6. >>> df.pivot('foo', 'bar', 'baz') A B C one 1 2 3 two 4 5 6 My DataFrame is structured like this:
name id x ---------------------- 0 john 1 0 1 john 2 0 2 mike 1 1 3 mike 2 0 And I want something like this:
1 2 # (this is the id as columns) ---------------------- mike 0 0 # (and this is the 'x' as values) john 1 0 But when I run the pivot method, it is saying:
*** ReshapeError: Index contains duplicate entries, cannot reshape Which doesn't makes sense, even in example there are repeated entries on the foo column. I'm using the name column as the index of the pivot, the first argument of the pivot method call.
As far as I can tell with updates to pandas, you have to use pivot_table() instead of pivot().
pandas.pivot_table(df,values='count',index='site_id',columns='week')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With