I have two dataframes. DF1 and DF2. I am comparing absolute distances between coordinate pairs from both. I want to populate a new dataframe that has rows for each df1 coordinate pair and a column for each df2 coordinate pair.
This would result in the absolute distance between each df1 pair and each df2 pair. This is my code so far and I'm struggling to figure out how to populate the new dataframe with each iteration.
`df_new = pd.DataFrame(index=df1.index.copy())
for idx_crime, x_crime in enumerate(df2['X_COORD']):
y_crime = df2['Y_COORD'].iloc[idx_crime]
for idx_subway, x_subway in enumerate(df1['X_COORD']):
y_subway = df1['Y_COORD'].iloc[idx_subway]
dist = np.sqrt((x_crime - x_subway)**2 + (y_crime - y_subway)**2)
append.df_new
return df_new`
It isn't running. Any ideas of how to fill out this new dataframe?
EDIT Sample Data
DF2 Coordinates:
X_COORD Y_COORD
0 1007314.0 241257.0
1 1043991.0 193406.0
2 999463.0 231690.0
3 1060183.0 177862.0
4 987606.0 208148.0
DF1 Coordinates:
X_COORD Y_COORD
0 1020671.0 248680.0
1 1019420.0 245867.0
2 1017558.0 245632.0
So df_new would look like this. Just the index numbers would work for column headings. I just wanted to show you how the data would look:
df2_coord0 df2_coord1 df2_coord2
df1_coord0 13356.72213 23318.81485 21207.59944
df1_coord1 12105.8096 24569.93244 19956.64481