1# filter rows in a dataframe by a condition on a column
2
3df_filtered = df.loc[df['column'] == value]
1In [96]: df
2Out[96]:
3 A B C D
4a 1 4 9 1
5b 4 5 0 2
6c 5 5 1 0
7d 1 3 9 6
8
9In [99]: df[(df.A == 1) & (df.D == 6)]
10Out[99]:
11 A B C D
12d 1 3 9 6
1# filter rows for year 2002 using the boolean expression
2>gapminder_2002 = gapminder[gapminder.year.eq(2002)]
3>print(gapminder_2002.shape)
4(142, 6)