0

I'm trying to update values of one data frame by performing calculations with a second data frame and update.

I simplified the code, since the problem seems to be a more general one.

At fist I make a copy a data frame by df_2 = df, since the values of df have to remain untouched, only the values of df_2 should be updated.

Then I collect indexes for certain case:

indexes = df_2[(df_2['lat'] == float(lat)) & (df_2['lon'] == float(lon))].index.tolist()

for index in indexes:
    if df_2.iloc[index]['value_age'] > 0:                                                        
        df_2.at[index,'value'] = 1.123456 
    else:
        continue

After df_2.at is performed, both df AND df_2, value for that particular index is updated to 1.23456. I have no clue why this is.

Kai
  • 67
  • 2
  • 10
  • "At fist I make a copy a data frame by `df_2 = df`" You are wrong, that does not create a copy. That is merely an assignment statement, that binds the name on the left to whatever object is on the right. **No copy is made**. Read the following for a good explanation: https://nedbatchelder.com/text/names.html – juanpa.arrivillaga Mar 24 '20 at 11:47
  • 1
    Awesome, thank you! You just made my day! I used df_2 = df.copy(). Now it works as I expected. Thanks for the link, now a lot of weird stuff from the past sense to me now! – Kai Mar 24 '20 at 11:55

0 Answers0