TheEmperor
TheEmperor

Reputation: 355

Removing rows from a DataFrame where column matches a specific value

I have a following DataFrame,

PDBID FirstResidue SecondResidue FirstChain ThirdResidue FourthResidue  \
0  1ffk.pdb         C208          G209          0         A665          A666   
1  1ffk.pdb         U325          G326          0         A305          A306   
2  1ffk.pdb        C2077         U2078          0        A1078         A1079   
3  1ffk.pdb         A790          A791          0        C1708         G1709   
4  1ffk.pdb        C2594         U2595          0        C1993         A1994  

SecondChain                        Pattern  Distance1  Distance2  
0           0  CG/AA Canonical ribose-zipper    2.79061    2.78089  
1           0  UG/AA Canonical ribose-zipper    2.74239    2.99667  
2           0  CU/AA Canonical ribose-zipper    2.69101    2.91463  
3           0  AA/CG Canonical ribose-zipper    3.04052    2.60353  
4           0  CU/CA Canonical ribose-zipper    2.69807    2.81067  

I want to remove rows where the value of either column Distance1 or Distance is more than 3.0. How can I do this using pandas?

Upvotes: 0

Views: 92

Answers (1)

unutbu
unutbu

Reputation: 880269

You could form a mask:

mask = (df['Distance1']<=3.0) & (df['Distance2']<=3.0)

and then select the rows with:

df[mask]

or

df.loc[mask]

Since I use df[col] to select columns, I prefer the df.loc[...] syntax to emphasize that I'm selecting rows.

Upvotes: 1

Related Questions