pygo

pandas 23

Dec 1st, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. $ python37
  2. Python 3.7.0 (default, Jul 26 2018, 06:52:13)
  3. [GCC 6.3.0] on linux
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import pandas as pd
  6. >>> df = pd.DataFrame({'PlaceTest':[21,21,22,22], 'Approved':[1,0,1,0]})
  7. >>> df
  8. PlaceTest Approved
  9. 0 21 1
  10. 1 21 0
  11. 2 22 1
  12. 3 22 0
  13. >>> df['Not Approved'] = df.groupby('PlaceTest')['Approved'].sum()
  14. >>> df
  15. PlaceTest Approved Not Approved
  16. 0 21 1 NaN
  17. 1 21 0 NaN
  18. 2 22 1 NaN
  19. 3 22 0 NaN
  20. >>> df = df.groupby('PlaceTest')['Approved', 'Not Approved'].sum().fillna("1").reset_index()
  21. >>> df
  22. PlaceTest Approved Not Approved
  23. 0 21 1 0.0
  24. 1 22 1 0.0
  25. >>> pd.__version__
  26. '0.23.3'
Add Comment
Please, Sign In to add comment