Python 尝试后使用copyWarning进行设置。loc

Python 尝试后使用copyWarning进行设置。loc,python,pandas,Python,Pandas,首先,我构建了一个新的数据框架。然后通过从帧中过滤一些数据来创建一个新的帧2。现在我想给frame2赋值: import numpy as np from pandas import DataFrame frame = DataFrame(np.arange(9).reshape((3, 3)), index=['a', 'c', 'd'], columns=['Ohio', 'Texas', 'California']) mask = frame['Texas'] > 1 print

首先,我构建了一个新的数据框架。然后通过从帧中过滤一些数据来创建一个新的帧2。现在我想给frame2赋值:

import numpy as np
from pandas import DataFrame

frame = DataFrame(np.arange(9).reshape((3, 3)), index=['a', 'c', 'd'], columns=['Ohio', 'Texas', 'California'])
mask = frame['Texas'] > 1
print frame[mask]
frame2 = frame.loc[mask]
frame2.loc['c', 'Ohio'] = 'me'
print frame2
但我得到了这个警告:

C:\Python27\lib\site-packages\pandas\core\indexing.py:461: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead
尽管我使用了推荐的.loc语法,但为什么我仍然收到此警告?我应该怎么做才能避免这个警告?

正在更改

frame2 = frame.loc[mask]


消除此警告。

我似乎在以下位置找到了一个可能的解决方案:。有人有其他好主意吗?你在这里的意图是什么?您想更新副本还是原件df@EdChum我想更新副本。
frame2 = frame.loc[mask].copy()