Puzzle 14: A Tale of One City

Let's solve a pandas DataFrame puzzle using Python functions.

We'll cover the following

Guess the output

Try to guess the output of the code below:

Press + to interact
import pandas as pd
cities = pd.DataFrame([
('Vienna', 'Austria', 1_899_055),
('Sofia', 'Bulgaria', 1_238_438),
('Tekirdağ', 'Turkey', 1_055_412),
], columns=['City', 'Country', 'Population'])
def population_of(city):
return cities[cities['City'] == city]['Population']
city = 'Tekirdağ'
print(population_of(city))

Quiz

Q

What is the output of the code above?

A)

1_055_412

B)

1055412

C)

Series([], Name: Population, dtype: int64)

D)
2    1055412
Name: Population, dtype: int64

Get hands-on with 1300+ tech skills courses.