我有以下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
我想删除其中任何列Distance1或Distance的值大于3.0的行。我怎么能用熊猫做到这一点?
答案 0 :(得分:1)
你可以形成一个面具:
mask = (df['Distance1']<=3.0) & (df['Distance2']<=3.0)
然后选择行:
df[mask]
或
df.loc[mask]
由于我使用df[col]
来选择列,因此我更喜欢df.loc[...]
语法来强调我正在选择行。