7

I read this documentation but I do not understand what the overwrite option actually does to the update process. I tested with a few cases but in each whether or not I set overwrite to True or False makes no difference. Can someone give an example where it does make a difference?

1 Answer 1

4

The difference is that when overwrite is set to false, it will only fill in missing values in the DataFrame that update was called on.

Based on the example from the link you supplied (using the default value overwrite=True):

df = pd.DataFrame({'A': [1, 2,3], 'B': [400, None, 600]})
new_df = pd.DataFrame({'B': [4, 5, 6],  'C': [7, 8, 9]})
df.update(new_df)

yields:

   A    B
0  1  4.0
1  2  5.0
2  3  6.0

whereas df.update(new_df, overwrite=False) yields:

   A      B
0  1  400.0
1  2    5.0
2  3  600.0
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.