[text] data

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.  
  20. # Q2. Create vertical bar charts for countries with population, growthrate, and gdp. 
  21. # Sample is given below 
  22. plt.subplot(2,2,1)
  23. plt.title("count by popula")
  24. df.groupby('country')['population'].mean().plot(kind='bar')
  25. plt.subplot(2,2,2)
  26. plt.title("cont by growthwte")
  27. df.groupby('country')['growthrate'].mean().plot(kind='bar')
  28. plt.subplot(2,2,3)
  29. plt.title("cont by gdp")
  30. df.groupby('country')['gdp'].mean().plot(kind='bar')
  31. #plt.show()
  32.  
  33. # Q3. Do the following in matplotlib
  34. plt.bar(df['country'],df['population'], color='b')
  35. for i in range (len(df['country'])):
  36. plt.text(i,df['population'][i],str(df['population'][i]),ha='center', va='bottom')
  37. plt.show()

Editor

You can edit this paste and save as new:


File Description
  • data
  • Paste Code
  • 09 May-2024
  • 1.46 Kb
You can Share it: