【发布时间】:2020-05-10 00:15:18
【问题描述】:
如果country 的值为“US”,我想为特征country_US 分配一个特定的值1。这是我尝试过的两件事,但收到警告并且 X_test 也没有更新 country_US 功能。
X_test[X_test['country']=='US].loc[:,'country_US']=1
与
X_test.loc[X_test['country']=='US].loc[:,'country_US']=1
警告 -
C:\Users\DELL\Anaconda3\lib\site-packages\pandas\core\indexing.py:671: SettingWithCopyWarning: 正在尝试在 DataFrame 中的切片副本上设置值
请参阅文档中的注意事项:https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy self._setitem_with_indexer(indexer, value)
【问题讨论】: