Python Pandas program to count Country wise population from a given dataset

In this python pandas program, we will count Country wise population from a given dataset using the pandas library.

Link for Dataset- https://www.kaggle.com/datasets/tanuprabhu/population-by-country-2020?resource=download

Steps to solve the program
  1. Import pandas library as pd.
  2. First, read the dataset using pd.read_csv().
  3. Now drop the unnecessary columns from the dataset using df.drop().
  4. Print the first 10 countries using df.head(10).
				
					import pandas as pd
df = pd.read_csv("population_by_country_2020.csv")
df1 = df.drop(['Yearly Change','Net Change','Density (P/Km²)','Land Area (Km²)',
              'Migrants (net)','Fert. Rate','Med. Age','Urban Pop %','World Share'],axis=1)
print(df1.head(10))
				
			

Output :

				
					0  Country (or dependency)  Population (2020)
0                   China         1440297825
1                   India         1382345085
2           United States          331341050
3               Indonesia          274021604
4                Pakistan          221612785
5                  Brazil          212821986
6                 Nigeria          206984347
7              Bangladesh          164972348
8                  Russia          145945524
9                  Mexico          129166028
				
			

write a DataFrame to a CSV file using a tab separato

replace all the NaN values with a scaler in a column of a Dataframe

Leave a Comment