Write a program to create pie chart of five most countries are affected by corona virus in 2020. Read the data from CSV file.
- Import matplotlib.pyplot module in program using import statement
- Import pandas module using import statement
- Read data from CSV file say “corona.csv”
- Display CSV file data on console
- Collect Country column data from dataframe object say df and store it in variable say “country_data”
- Collect Cases column data from dataframe object say df and store it in variable say “cases_data”
- Create pie chart using plt.pie method and pass country_data and cases_data as an argument to it
- Write title for Pie chart using plt.title method
- Show pie chart on console using show method
Below is implementation code/Source code
import matplotlib.pyplot as plt import pandas as pd # read data from CSV file df = pd.read_csv("corona.csv") print(df) country_data = df["Country"] cases_data = df["Cases"] plt.pie(cases_data,labels=country_data,autopct='%1.1f%%') plt.title("top 5 Countries affected by COvid-19 with highest number of Cases") plt.legend() plt.show()
Below is Output
Country Cases Deaths Region 0 United States 43246791 6,96,918 North America 1 India 33531498 4,45,801 Asia 2 Brazil 21247094 5,91,518 South America 3 United Kingdom 7496543 1,35,455 Europe 4 Russia 7333557 2,00,625 Europe >>>
Below is pie chart showing topmost 5 countries affected by covid-19
Related python programs
- Write a program to create Pandas series from dictionary of values and nd array.
- Write a program to perform mathematical operation on two Pandas series object.
- Write a program to create data frame quarterly sales where each row contain the item category, item name and expenditure. Group the row by the category and print the total expenditure per category.
- Write a program to create data frame based on e-commerce data and generate descriptive statistics.
- Write a program to create data frame for examination result and display row labels, column labels data types of each column and the dimensions.