import pandas as pd
import numpy as np
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
d = [10, 21, 10, 21, 21, 10, 23, 23, 25, 25]
f = [0, 1, 1, 2, 0, 0, 2, 2, 0, 0]
df = pd.DataFrame({'gid': a, 'x': d, 'y': f})
print(df)
aa = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
bb = [10, 21, 10, 21, 21, 10, 23, 23, 25, 25]
cc = [0, 1, 1, 2, 0, 0, 2, 2, 0, 0]
dd = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
ee = [10, 21, 10, 21, 21, 10, 23, 23, 25, 25]
ff = [0, 1, 1, 2, 0, 0, 2, 2, 0, 0]
gg = [10, 21, 10, 21, 21, 10, 23, 23, 25, 25]
df_ = pd.DataFrame({'id': aa, 'source': bb, 'target': cc, 'x_source': dd, 'x_target': ee, 'y_source': ff, 'y_target': gg})
print(df_)
df['x_y'] = df[['x', 'y']].apply(tuple, axis=1)
print(df)
df_dict = df[['x_y', 'gid']].set_index('gid').to_dict()['x_y']
print(df)
for index, row in df_.iterrows():
print(index, row['source'])
if row['source'] in df_dict:
df_.loc[df_['source'] == row['source'], 'x_source'] = df_dict[row['source']][0]
df_.loc[df_['source'] == row['source'], 'y_source'] = df_dict[row['source']][1]
if row['target'] in df_dict:
df_.loc[df_['target'] == row['target'], 'x_target'] = df_dict[row['target']][0]
df_.loc[df_['target'] == row['target'], 'y_target'] = df_dict[row['target']][1]
print(df_)