【发布时间】:2017-05-07 08:05:10
【问题描述】:
我正在尝试通过索引选择来设置数据框中列的值。
myindex = (df['city']==old_name) & (df['dt'] >= startDate) & (df['dt'] < endDate)
new_name = 'Boston2
df['proxyCity'].ix[myindex ] = new_name
在上面,给定myindex中的条件,我想在proxyCity列中分配值Boston2
C:\Users\blah\Anaconda3\lib\site-packages\pandas\core\indexing.py:132: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
self._setitem_with_indexer(indexer, value)
在不引入文档中概述的问题的情况下,做我想做的事情的正确方法是什么。
此链接using pandas to select rows conditional on multiple equivalencies 中的答案似乎是按照我实现它的方式进行的。
我不确定这样做的正确方法是什么。
【问题讨论】: