替换值并获取“ SettingWithCopyWarning:试图在来自DataFrame的切片的副本上设置一个值”

时间:2020-09-28 18:04:03

标签: python pandas

我正在尝试用“否”和“是”替换0和1。

我知道将会有一种更简洁的书写方式,但是主要的问题是我无法理解为什么我会收到警告并且代码无法正常工作。

age_group_clean['has_health_problem'].replace(['0'],'No', inplace=True)
age_group_clean['has_health_problem'].replace(['1'],'Yes', inplace=True)

/Users/kerrimac/opt/anaconda3/lib/python3.8/site-packages/pandas/core/generic.py:6746: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  self._update_inplace(new_data)

0 个答案:

没有答案