Pandas 3 Filter Observations Flashcards

1
Q

A Filter is a way to

A

Pick out a subset of rows

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When using loc[] you may also pass which specific columns to include

A

DF.loc[119, [‘name’, ‘pos’, ‘stdev’]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly