Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. In []: dframe1
  2. Out[]:
  3. letter A B C D
  4. city
  5. LA 0 1 2 3
  6. SF 4 5 6 7
  7.  
  8. # Use stack to pivot the columns into the rows
  9. In []: dframe1.stack()
  10. Out[]:
  11. city letter
  12. LA A 0
  13. B 1
  14. C 2
  15. D 3
  16. SF A 4
  17. B 5
  18. C 6
  19. D 7
  20. dtype: int64
  21.  
  22. # Use unstack to pivot the rows into the columns
  23. # We can choose which level (name) to unstack by
  24. In []: dframe1.stack().unstack()
  25. Out[]:
  26. letter A B C D
  27. city
  28. LA 0 1 2 3
  29. SF 4 5 6 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement