What does the `overwrite` parameter do in the Pandas DataFrame.update () function?

I read this documentation, but I donโ€™t understand what the overwrite option actually does for the update process. I tested several cases, but in each I set overwrite to True or False does not matter. Can someone give an example where it matters?

+7
python pandas dataframe
source share
1 answer

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

According to the example from the link you provided (using the default value of 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) 

gives:

  AB 0 1 4.0 1 2 5.0 2 3 6.0 

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

  AB 0 1 400.0 1 2 5.0 2 3 600.0 
+4
source share

All Articles