0

This question might look like duplicate question of below posts [1, 2, 3] but in fact, I believe, it's not.

[1] How to deal with SettingWithCopyWarning in Pandas [2] Pandas DataFrame: SettingWithCopyWarning: [3]

The warning doesn't disappear even with deepcopy() and .loc[:, 'column_name']. The object id had changed, and still allocating the operated results to new column results the warning.

What would be the proper way of doing this?

import copy

temp = filtered_df["category"] + ") " + filtered_df["name"]

print(id(temp))               # 5336536736
temp = temp.copy()
print(id(temp))               # 5336488448
temp = copy.deepcopy(temp)
print(id(temp))               # 5336538944
print(temp)
filtered_df.loc[:, 'cat_name'] = temp
filtered_df
Warning

enter image description here

0 Answers0