0

I have df1 and df2. Each dataframe contains an ID column. Each dataframe also contains a geometry column. I would like to calculate the distance between each dataframe's geometry column only for rows where ID's match in each dataframe.

I would imagine it looks something like this but can't figure it out:

for geom in df1.geometry:
    if df1['system_id'] == df2f['systemID']:    
        df1['distance'] = [geom.distance(df2.geometry[0].boundary) for geom in df1.geometry]
Stephen
  • 37
  • 9
  • Something like this? `distance = df1[df1['system_id'] == df2['systemID']].geometry.distance(df2.geometry[0].boundary)` Distance here might not have the same number of rows as df1. – cornifer Dec 01 '22 at 20:35

1 Answers1

0

There's the function .equals()

df1['system_id'].equals(df2f['systemID'])

which will return a boolean

  • Not sure how I'd implement that into the rest of my code as I also need to compare values in each df's geometry column – Stephen Dec 01 '22 at 20:27
  • In that case, I guess this should be helpful then [https://stackoverflow.com/questions/36909977/update-row-values-where-certain-condition-is-met-in-pandas](https://stackoverflow.com/questions/36909977/update-row-values-where-certain-condition-is-met-in-pandas) – Diogo Dinis Dec 01 '22 at 20:55