ekaterinahellokitty

Pie

Sep 30th, 2022
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. regions = ['na_sales', 'jp_sales', 'eu_sales']
  2.  
  3. for i in range(3):
  4. top_platforms = (df_period.groupby('platform')[regions[i]].sum().
  5. reset_index().
  6. sort_values(regions[i], ascending = False, ignore_index = True).
  7. head(5))
  8.  
  9. top_platforms = (top_platforms.
  10. append({
  11. 'platform': 'Other_platform',
  12. regions[i]: df_period[regions[i]].sum() - top_platforms[regions[i]].sum()},
  13. ignore_index= True))
  14.  
  15. import matplotlib.pyplot as plt
  16.  
  17. fig, ax = plt.subplots(1,3)
  18.  
  19. ax[i].pie(top_platforms[regions[i]], labels = top_platforms['platform'], autopct="%1.1f%%", frame = True)
  20. ax[i].axis('equal')
  21. ax[i].set_title(top_platforms.columns[i].split(' ')[0].upper())
  22.  
  23. plt.show()
Add Comment
Please, Sign In to add comment