mardi 27 août 2019

Nested for and if loops applied on each row of the dataframe - Python

i am working on 2 dataframes. The first data frame have x and y coordinates in this form. The East coordinate have the "x" coordinates and North coordinates have the "y" coordinates.

    Blast Hole        East Coordinate                      North Coordinate
105,100,99      16764.83,16752.74,16743.1       107347.67,107360.32,107362.96

I have another dataframe which have millions of rows representing basically a cubical dimensions of x, y and z with their lengths and widths. The structure of the dataframe looks like this:

XMORIG           YMORIG        ZMORIG         XC          YC             ZC
14212.37        104364.2        1300    17499.87        105601.7        2852.5
14212.37        104364.2        1300    17499.87        105601.7        2867.5
14212.37        104364.2        1300    17474.87        105601.7        2867.5
14212.37        104364.2        1300    17499.87        105626.7        2852.5
14212.37        104364.2        1300    17499.87        105626.7        2867.5
14212.37        104364.2        1300    17499.87        105676.7        2867.5
14212.37        104364.2        1300    17524.87        105701.7        2867.5

Where XC, YC and ZC are the centroid of cubes in x, y and z axis.

what i am looking forward is to write a function with for and if nested loops where the functions picks x and y coordinates from the first database and looks in rows of second database where the x and y coordinates lie within a fixed distance from x and y centroids in the second database. For rows in which the x and y coordinates have less than 12.5 m of distance from x and y centroids, i want to pick all those rows and create a new df from it.

The code i have tried till now is:

def ValidCampaign_rows(row):

    for i in x3:

        if i - Xcentroid <= abs(12.5):

            for i in y3:

                if i - Ycentroid <= abs(12.5):

I am not sure how to write after to pick those rows and keep writing in a new df for each coordinate in the list.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire