Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. value identifier
  2. 2007-01-01 0.781611 55
  3. 2007-01-01 0.766152 56
  4. 2007-01-01 0.766152 57
  5. 2007-02-01 0.705615 55
  6. 2007-02-01 0.032134 56
  7. 2007-02-01 0.032134 57
  8. 2008-01-01 0.026512 55
  9. 2008-01-01 0.993124 56
  10. 2008-01-01 0.993124 57
  11. 2008-02-01 0.226420 55
  12. 2008-02-01 0.033860 56
  13. 2008-02-01 0.033860 57
  14.  
  15. df.groupby('identifier')
  16.  
  17. df.groupby('identifier').plot(subplots=True)
  18.  
  19. df.groupby('identifier').plot(subplots=False)
  20.  
  21. plt.subplots(3,3)
  22. df.groupby('identifier').plot(subplots=True)
  23.  
  24. import pandas as pd
  25. from numpy.random import randint
  26. import matplotlib.pyplot as plt
  27.  
  28.  
  29. df = pd.DataFrame(randint(0,10,(200,6)),columns=list('abcdef'))
  30. grouped = df.groupby('a')
  31. rowlength = grouped.ngroups/2 # fix up if odd number of groups
  32. fig, axs = plt.subplots(figsize=(9,4),
  33. nrows=2, ncols=rowlength, # fix as above
  34. gridspec_kw=dict(hspace=0.4)) # Much control of gridspec
  35.  
  36. targets = zip(grouped.groups.keys(), axs.flatten())
  37. for i, (key, ax) in enumerate(targets):
  38. ax.plot(grouped.get_group(key))
  39. ax.set_title('a=%d'%key)
  40. ax.legend()
  41. plt.show()
  42.  
  43. pd.pivot_table(df.reset_index(),
  44. index='index', columns='identifier', values='value'
  45. ).plot(subplots=True)
  46.  
  47. pd.pivot_table(df.reset_index(),
  48. index='index', columns='identifier', values='value'
  49. )
  50.  
  51. identifier 55 56 57
  52. index
  53. 2007-01-01 0.781611 0.766152 0.766152
  54. 2007-02-01 0.705615 0.032134 0.032134
  55. 2008-01-01 0.026512 0.993124 0.993124
  56. 2008-02-01 0.226420 0.033860 0.033860
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement