Skip to main content
added 380 characters in body
Source Link
Alter
  • 3.5k
  • 5
  • 34
  • 57

you can decouple them by making an actual copy (a copy is a separate object)

df_backup = df.copy()

as Anthony Sottile pointed out, you were creating another reference to your original dataframe rather than creating a new object. Which means you could change either your df or df_backup and both would show that change. He also suggested a good link to help understand this

you can decouple them by making an actual copy (a copy is a separate object)

df_backup = df.copy()

you can decouple them by making an actual copy (a copy is a separate object)

df_backup = df.copy()

as Anthony Sottile pointed out, you were creating another reference to your original dataframe rather than creating a new object. Which means you could change either your df or df_backup and both would show that change. He also suggested a good link to help understand this

Source Link
Alter
  • 3.5k
  • 5
  • 34
  • 57

you can decouple them by making an actual copy (a copy is a separate object)

df_backup = df.copy()