I have three dataframes that I am comparing, where I have stored several data, one where is the information of my interest, which is the one I want to complete. The second one where is the column with the coordinates that I want to add to my general dataframe and the third one where are stored the indexes of the two previous dataframes where the values correspond.
It is a little confusing, but I put an example where you can see it better:
Dataframe 1:
| index | n_tree |
|---|---|
| 247 | 1 |
| 248 | 2 |
Dataframe 2:
| index | coords |
|---|---|
| 1400 | (20,47) |
| 1401 | (30,85) |
dataframe 3:
| index | index_dataframe_1 | index_dataframe_2 |
|---|---|---|
| 0 | 247 | 1401 |
My intention is that my general dataframe contains the correct coordinate column. as follow:
| index | n_tree | coords |
|---|---|---|
| 247 | 1 | (30,85) |
I have tried to assign it with .iloc, .loc, .at but I get the following error:
for idx, rw in dataframe_3.iterrows():
coords = dataframe_1.loc[rw.index_dataframe_2, "coords"]
dataframe_2.loc[int(rw.index_dataframe_1), "coords"] = coords
ValueError: Must have equal len keys and value when setting with an iterable.