0

i have x and y coordinates as:

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

its basically like three points (x1, y1), (x2, y2) and (x3, y3)

in the dataframe:

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

i want to choose only those rows in which the x and y of one set of coordinates are less than 12.5 of the same row of the dataframe from column XC and YC.

i have tried:

c = (x3,y3)

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

print(df1)

but not getting the desired result.

The desired outcome would be :

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
0

1 Answer 1

2

You can zip bot list and filter in list comprehension for list of DataFrames and then concat together, also change absolute values for Series with difference of i and j values if necessary:

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
Sign up to request clarification or add additional context in comments.

3 Comments

for this code as well it is not giving the desired result. i want only those rows in which x and y both are within the limit of 12.5 distance. this code is producing some rows which have only x values valid and some only y values fulfilling condition. so as a desired outcome only 3 rows would come out suitable for 3 data points. one for each.
@zsh_18 - Answer was changed.
getting the error "TypeError: cannot compare a dtyped [bool] array with a scalar of type [bool]"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.