Python-Programming-Lesson-Notes

Selection of Individual Values

Assume Pandas has been imported into your notebook and the Gapminder GDP data for Europe has been loaded:

Python

import pandas as pd

df = pd.read_csv('data/gapminder_gdp_europe.csv', index_col='country')

Write an expression to find the Per Capita GDP of Serbia in 2007.

Solution The selection can be done by using the labels for both the row (“Serbia”) and the column (“gdpPercap_2007”): Python
print(df.loc['Serbia', 'gdpPercap_2007'])
The output is Output
9786.534714

Expisode 2 Exercise 3