Pandas 3 Filter Observations Flashcards
1
Q
A Filter is a way to
A
Pick out a subset of rows
2
Q
Method to find row by specific index value
A
Loc[] — note the brackets, loc is more like a retrieving a value from a dictionary than calling a method
Pass index value
DF.loc[119]
Or
Multiple rows:
DF.loc[119, 1886, 925]
3
Q
When using loc[] you may also pass which specific columns to include
A
DF.loc[119, [‘name’, ‘pos’, ‘stdev’]]
4
Q
How is loc[] most commonly used?
A
By using boolean indexing, which is passing a series of boolean values and the method returns rows which are true
is_a_rb = df[‘position’] == ‘RB’
DF.loc[is_a_rb, [‘name’, ‘position’]