Guided Project: Clean and Analyze Employee Exit Survey - Setting with Copy warning

I am on part 5 of the guided project “clean and analyze employee exit survey”. The instruction was to use vectorized string method to extract the year.

Screen Link:

My Code:

dete_resignations['cease_date'] = dete_resignations['cease_date'].str.split('/').str[-1]

What I expected to happen:
I thought this would return a column with just the year.

What actually happened:

<ipython-input-22-69e33acb3bbd>:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  dete_resignations['cease_date'] = dete_resignations['cease_date'].str.split('/').str[-1]

I am lost. Please help.

Hi @r.naga.ny,

Welcome to the Community!

Exactly in this case, try to run the following line of code right before your line of code:

dete_resignations = dete_resignations.copy()

If you want to learn more about how to deal with SettingWithCopyWarning in different cases, you can find useful this article.