Jay
Jay

Reputation: 67

filter data frame with two conditions columns?

I have data set like this,

S.No.   Counts  No.rep  Fram
1   3   4   UNC84A
2   10  4   UNC84A
3   7   4   UNC84A
4   10.3    4   UNC84A
5   7   1   NTUD19
6   181 3   ALR6IP4
7   7   3   ALR6IP4
8   21  3   ALR6IP4

I would like to filter "if No.rep>=3" then select column which has "Counts>= 10". Also, when No.rep < 3, I would required to have columns with Counts < 10 as well.

This is my required output

S.No.   Counts  No.rep  Fram
2   10  4   UNC84A
4   10.3    4   UNC84A
5   7   1   NTUD19
6   181 3   ALR6IP4
8   21  3   ALR6IP4

Upvotes: 0

Views: 132

Answers (1)

lroha
lroha

Reputation: 34291

You can try:

df[df["No.rep"] >= 3 & df["Counts"] >= 10,]
S.No. Counts No.rep    Fram
    2   10.0      4  UNC84A
    4   10.3      4  UNC84A
    6  181.0      3 ALR6IP4
    8   21.0      3 ALR6IP4

EDIT:

Do you want an OR condition like so:

df[(df["No.rep"] >= 3 & df["Counts"] >= 10) | (df["No.rep"] < 3 & df["Counts"] < 10),]

  S.No. Counts No.rep    Fram
      2   10.0      4  UNC84A
      4   10.3      4  UNC84A
      5    7.0      1  NTUD19
      6  181.0      3 ALR6IP4
      8   21.0      3 ALR6IP4

Upvotes: 3

Related Questions