[text] data1

Viewer

  1. #Q1. Find the data in the dataframe below. c
  2. dic = {'country': ['India', 'Japan', 'China', 'USA', 'Russia'],
  3. 'population': [1425.7, 123.3, 1425.4, 340, 144.4],
  4. 'growthrate': [6.72, 1.47, 8.5, 8.8, 4.7],
  5. 'gdp':[3730,4231,17786,70248,12194]}
  6. df = pd.DataFrame(dic)
  7. df
  8. # Create Pie charts for countries with population, growthrate, and gdp. Exclude any one by 15%.
  9. # Sample is given below
  10. plt.subplot(2,2,1)
  11. plt.title('countries with population')
  12. df.groupby('country')['population'].mean().plot(kind='pie',explode=[0.15,0,0,0,0])
  13. plt.subplot(2,2,2)
  14. plt.title('countries with growthrate')
  15. df.groupby('country')['growthrate'].mean().plot(kind='pie',explode=[0.15,0,0,0,0])
  16. plt.subplot(2,2,3)
  17. plt.title('countries with gdp')
  18. df.groupby('country')['gdp'].mean().plot(kind='pie', explode=[0.15,0,0,0,0])
  19. plt.legend(loc='upper left') #lower left #lower right
  20. plt.savefing('chart1.jpg')
  21. plt.show
  22.  
  23. # Q2. Create vertical bar charts for countries with population, growthrate, and gdp. 
  24. # Sample is given below 
  25. plt.subplot(2,2,1)
  26. plt.title("count by popula")
  27. df.groupby('country')['population'].mean().plot(kind='bar')
  28. plt.subplot(2,2,2)
  29. plt.title("cont by growthwte")
  30. df.groupby('country')['growthrate'].mean().plot(kind='bar')
  31. plt.subplot(2,2,3)
  32. plt.title("cont by gdp")
  33. df.groupby('country')['gdp'].mean().plot(kind='bar')
  34. #plt.show()
  35.  
  36. # Q3. Do the following in matplotlib
  37. plt.bar(df['country'],df['population'], color='b')
  38. for i in range (len(df['country'])):
  39. plt.text(i,df['population'][i],str(df['population'][i]),ha='center', va='bottom')
  40. plt.show()

Editor

You can edit this paste and save as new:


File Description
  • data1
  • Paste Code
  • 09 May-2024
  • 1.55 Kb
You can Share it: