Answer to Question #306138 in Python for johnie

Question #306138

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


1
Expert's answer
2022-03-04T13:22:21-0500
#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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS