A value is trying to be set on a copy of a slice from a DataFrame

I keep getting the semi-error listed in the title here. I know that I can use .copy(), but I am having trouble applying it without getting other errors. What changes would I have to make to my code below in order to not get this error anymore?

Screen Link: Learn data science with Python and R projects

My Code:

dete_resignations['institute_service'] = dete_resignations['cease_date'] - dete_resignations['dete_start_date']

I also had the same error when doing this to extract the years alone:

years_alone = '([2][0][0-1][0-9])'

dete_resignations['cease_date'] = dete_resignations['cease_date'].str.extract(years_alone)

What should I do in the future?

First and foremost, have you read this detailed blog post on this subject? It is a very common error and is well worth reading.

I’m not so sure you can simply modify the code you have provided in order to avoid this warning message. I believe you would need to provide the line(s) of code where you defined dete_resignations in order to get at the root of this message. As a “generic example”, it should look something like:

dete_resignations = dete_survey_updated[dete_survey_updated['separationtype'] == 'Resignation'].copy()