0

I have a pandas data frame with a column called Job Title, and I have a list with allowed Job Titles. I want to check the Job Title column against the allowed list, and if it is not allowed, make the value blank ("").

This is the code I am using:

df_detail.loc[~df_detail["Job Title"].isin(allowed_jobs), "Job Title"] = ""

It appears to work but I am getting this warning message which I would rather not cause at all. What am I doing wrong here?

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

Thanks!

niko
  • 5,253
  • 1
  • 12
  • 32
  • The problem is not this code line which works when you didn't make a copy before. You probably have sliced your dataframe `df_detail` before this line. – Corralien Dec 04 '21 at 14:09
  • @Corralien thanks, you were right. I did this earlier up on the original df and it stopped the message. thank you – djsammyb Dec 04 '21 at 14:19

0 Answers0