Chiefir
Chiefir

Reputation: 2671

How to filter rows in Pandas based on specific value in 1 column

I have a csv, like this (no headers):

a1   b1  3
a2   b2  5 
a3   b3  8

I want to get all rows, where values in last column is >4. How can I do that?

P.S. This is why this is not duplicated question - in the link above columns are named, my columns are unnamed.

Upvotes: 1

Views: 45

Answers (1)

jezrael
jezrael

Reputation: 862511

You can use boolean indexing with iloc for select last column:

df = df[df.iloc[:, -1] > 4]
print (df)
    0   1  2
1  a2  b2  5
2  a3  b3  8

Detail:

print (df.iloc[:, -1])
0    3
1    5
2    8
Name: 2, dtype: int64

Upvotes: 1

Related Questions