繁体   English   中英

多个条件-在pandas数据框中选择行

[英]Multiple conditions - Selecting rows in pandas dataframe

我有x和y坐标为:

x = (16764.83, 16752.74, 16743.1)
y = (107347.67, 107360.32, 107362.96)

它基本上就像三个点(x1, y1), (x2, y2) and (x3, y3)

在数据框中:

print (bf)
     XMORIG    YMORIG  ZMORIG        XC         YC      ZC
0  14212.37  104364.2    1300  16774.83  107357.67  2852.5
1  14212.37  104364.2    1300  17499.87  105601.70  2867.5
2  14212.37  104364.2    1300  17474.87  105601.70  2867.5
3  14212.37  104364.2    1300  17499.87  105626.70  2852.5
4  14212.37  104364.2    1300  17499.87  105626.70  2867.5
5  14212.37  104364.2    1300  17499.87  105676.70  2867.5
6  14212.37  104364.2    1300  17524.87  105701.70  2867.5
7  14212.37  104364.2    1300  16762.74  107370.32  2882.5
8  14212.37  104364.2    1300  16753.10  107372.96  2897.5

我只想选择其中一组坐标的x和y小于XC和YC列的数据帧同一行的12.5的行。

我努力了:

c = (x3,y3)

for i in c:
    df1 = (bf.loc[(bf['XC']-i <= abs(12.5))] & (bf['YC'] - i <= abs(12.5)))

print(df1)

但没有得到理想的结果。

理想的结果将是:

print (df)
     XMORIG    YMORIG  ZMORIG        XC         YC      ZC
0  14212.37  104364.2    1300  16774.83  107357.67  2852.5
1  14212.37  104364.2    1300  16762.74  107370.32  2882.5
2  14212.37  104364.2    1300  16753.10  107372.96  2897.5

您可以压缩僵尸列表和过滤器列表修真的列表DataFrame秒,然后concat在一起,也改变绝对值为系列的区别ij值,如果必要的:

x = (16764.83, 16752.74, 16743.1)
y = (107347.67, 107360.32, 107362.96)

dfs = [(bf[(bf['XC']-i) <= 12.5 & ((bf['YC'] - j) <= 12.5)]) for i, j in zip(x, y)]
#if necessary absolute values of difference Series
#dfs = [(bf[((bf['XC']-i).abs()<=12.5)&((bf['YC']-j).abs()<=12.5)]) for i, j in zip(x, y)]

df = pd.concat(dfs, ignore_index=True)
print (df)
     XMORIG    YMORIG  ZMORIG        XC         YC      ZC
0  14212.37  104364.2    1300  16774.83  107357.67  2852.5
1  14212.37  104364.2    1300  16762.74  107370.32  2882.5
2  14212.37  104364.2    1300  16753.10  107372.96  2897.5

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM