Here is my base DF I am working with.
d={'ID': [3,4], 'SHAPE.x': [340329.0,3329433.0], 'SHAPE.y': [3329.0,0]}
d2={'ID': [4,3], 'SHAPE.x': [3329600.0,340328.0], 'SHAPE.y': [111,222]}
df = pd.DataFrame(data=d, index=[0,1])
df2 = pd.DataFrame(data=d2, index=[0,1])
print(df)
ID SHAPE.x SHAPE.y
0 3 340329.0 3329.0
1 4 3329433.0 0.0
this is what I am trying to do but its not saving. I already know this is terrible with large datasets but it helps sometimes to write the logic out like this.
for index, row in df.iterrows():
for index2, row2 in df2.iterrows():
if row['ID'] == row2['ID']:
if np.isclose(row['SHAPE.x'], row2['SHAPE.x']) == True:
row['SHAPE.x'] = row2['SHAPE.x']
else:
pass
this is the result I am looking for:
ID SHAPE.x SHAPE.y
0 3 340328.0 3329.0
1 4 3329433.0 0.0
I have tried a few one liners like this below but its not giving the correct result. I dont think I want to do a merge though with the extra columns and I only want to copy one column over.
out = df.loc[(df['ID'] == df2['ID']) & (np.isclose(df['SHAPE.x'], df2['SHAPE.x']) == True), 'SHAPE.x'] = df2['SHAPE.x']
print(out)
0 3329600.0
1 340328.0