1import pandas as pd
2import numpy as np
3df = pd.DataFrame({'A': 'foo bar foo bar foo bar foo foo'.split(),
4 'B': 'one one two three two two one three'.split(),
5 'C': np.arange(8), 'D': np.arange(8) * 2})
6print(df)
7sub_df = df.loc[df['A'] == 'foo'] # Subset based on specific A value
1# does year equals to 2002?
2# is_2002 is a boolean variable with True or False in it
3>is_2002 = gapminder['year']==2002
4>print(is_2002.head())
50 False
61 False
72 False
83 False
94 False
10# filter rows for year 2002 using the boolean variable
11>gapminder_2002 = gapminder[is_2002]
12>print(gapminder_2002.shape)
13(142, 6)