Why is `.copy()` needed to create the `killed` DataFrame in the "Working with Missing Data" lesson, step "2.Verifying the Total Columns"?

Screen Link: https://app.dataquest.io/m/370/working-with-missing-data/2/verifying-the-total-columns

The Instructions state:
We created a dataframe killed, containing the five columns that relate to people killed in collisions.

Here’s the code that does that:

killed_cols = [col for col in mvc.columns if 'killed' in col]
killed = mvc[killed_cols].copy()

Why can’t killed simply be assigned as killed = mvc[killed_cols]? Why must .copy() be used?

Thanks

PS: The DataFrame killed only has four columns not five, so the instructions should be edited to read:

“We created a dataframe killed, containing the four columns that relate to people killed in collisions.”

Hi @quinones

Go throught the below post, it may give your answer.

1 Like

Quite helpful, thanks!

1 Like