Answer to Question #305376 in Python for Francis

Question #305376
  1. Count and display the number of cities per country.
  2. Count and display the country which is a member of the EU (EU = yes) and not a member of the EU (EU = no).
  3. Find and display the country with the highest and lowest total population.
  4. Count and display the country with a coastline (coastline = yes) and without a coastline (coastline = no)
1
Expert's answer
2022-03-03T09:59:53-0500
import pandas as pd
dic = {'countries': ['England', 'France', 'Brazil', 'Germany', 'Portugal', 'Italy'], 'Population': [5000000, 2000000, 500000, 2500000, 1000000, 3000000], 'membership': ['yes', 'yes', 'no', 'yes', 'yes', 'yes'], 'no_per_cities': [100, 85, 25, 78, 52, 68], 'coast_line': ['yes', 'yes', 'no','yes', 'yes','yes'] }
df = pd.DataFrame(dic)
#1.Count and display the number of cities per country.
df['no_per_cities']



#2.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['membership'] == 'yes']['countries']
df[df['membership'] == 'yes']['countries'].count()



df[df['membership'] == 'no']['countries']
df[df['membership'] == 'no']['countries'].count()



#3.Find and display the country with the highest and lowest total population.
df[df['Population'] == df['Population'].max()]['countries']
df[df['Population'] == df['Population'].min()]['countries']



#4.Count and display the country with a coastline (coastline = yes) and without a coastline (coastline = no)
df[df['coast_line'] == 'yes']['countries']
df[df['coast_line'] == 'yes']['countries'].count()



df[df['coast_line'] == 'no']['countries']
df[df['coast_line'] == 'no']['countries'].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