dancemc15 dancemc15 - 1 year ago 172
Python Question

How do I only look at certain rows in pandas dataframe?

I want to only look at the information of rows that correspond with 'U' and 'L' and 'R' under the category 'LU'. What exactly do I have to write to grab that specific data?

1 E
2 U
3 R
4 L
5 R

test = data[data['LU'] == 'U' | 'L' | 'R' ]

I thought it might be the following statement above, but I got an error. 'U' 'L' and 'R' are also not integers.

Answer Source

method 1

data.query('LU in ("U", "L", "R")')

method 2


both result in

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download