1. Open and read the countrycities.csv file.
2. Count and display the number of cities per country.
3. Count and display the country which is a member of the EU (EU = yes) and not a member of the EU (EU = no).
4. Find and display the country with the highest and lowest total population.
5. Count and display the country with a coastline (coastline = yes) and without a coastline (coastline = no).
THIS IS THE LINK OF countrycities if you can help me with this i badly need this, i am just a student : https://drive.google.com/drive/folders/1dFoUHbPrBo3hiOJY_PTccdlQXSM4YJ4s?usp=sharing
#Import library
import pandas as pd
#Navigate to the folder
#Open and read the countrycities.csv file
df=pd.read_csv("C:/Max/Q306138/countrycities.csv")
df.nunique()
#. Count and display the number of cities per country.
df.groupby('country')['city'].nunique()
#Count and display the country which is a member of the EU (EU = yes) and not a member of the EU (EU = no).
df[df['EU'] == 'yes']['country']
df[df['EU'] == 'yes']['country'].count()
#3.Find and display the country with the highest and lowest total population.
df[df['population'] == df['population'].max()]['country']
df[df['population'] == df['population'].min()]['country']
#5. Count and display the country with a coastline (coastline = yes) and without a coastline (coastline = no).
#With a coastline
df[df['coastline'] == 'yes']['country']
df[df['coastline'] == 'yes']['country'].count()
#Without a coastline
df[df['coastline'] == 'no']['country']
df[df['coastline'] == 'no']['country'].count()
Comments
Leave a comment