Nikos Kakonas
Nikos Kakonas

Reputation: 11

Setting With Copy Warning when trying to change value from a column

I am trying to do the following.

df_county_outcomes['county'] = df_county_outcomes['county'].apply(lambda x : '0' + str(x) if len(str(x)) == 1 else str(x))

I get the correct result but the SettingWithCopyWarning will always be there. Can someone help? Thanks a lot in advance!

Upvotes: 1

Views: 33

Answers (1)

cmauck10
cmauck10

Reputation: 163

It could be due to a few reasons. This article helped me immensely.

TLDR is you can use pd.set_option('mode.chained_assignment', None) to suppress that warning if you are certain what you're doing is okay. In your case it looks like you can suppress the warning.

Upvotes: 0

Related Questions