Pandas Brain Teasers by Miki Tebeka

Pandas Brain Teasers by Miki Tebeka

Author:Miki Tebeka [Miki Tebeka]
Language: eng
Format: epub
Publisher: Pragmatic Bookshelf
Published: 2021-08-30T00:00:00+00:00


Further Reading

Returning a View Versus a Copy in the Pandas Documentation

http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

DataFrame.loc Documentation

http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html

Puzzle 14 A Tale of One City

population.py

​ ​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))

Guess the Output



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.