what is the difference between target = train[‘claim’] and target = train[‘claim’].copy()?

Considering train is a Pandas dataframe,
what is the difference between these two?

  • target = train['claim']‍
  • target = ‍train['claim'].copy()‍

Since both these code snippets are used to assign the value of the column to a target variable, how are they different?


target = train['claim'] means that target will point to the exact same object stored in train['claim']. Any modification done to this object via either target or train['claim'] will affect both.

target = train['claim'].copy() means you’re creating a copy of whatever’s in train['claim'] and storing it to target. Subsequent modifications to the object in traint['claim'] won’t affect target, and vice-versa.