Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In []: dframe1
- Out[]:
- letter A B C D
- city
- LA 0 1 2 3
- SF 4 5 6 7
- # Use stack to pivot the columns into the rows
- In []: dframe1.stack()
- Out[]:
- city letter
- LA A 0
- B 1
- C 2
- D 3
- SF A 4
- B 5
- C 6
- D 7
- dtype: int64
- # Use unstack to pivot the rows into the columns
- # We can choose which level (name) to unstack by
- In []: dframe1.stack().unstack()
- Out[]:
- letter A B C D
- city
- LA 0 1 2 3
- SF 4 5 6 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement