当我在具有两列和数值的数据框上运行以下语句时:
df.ix[df['A'] == value, 'B'] = 3600 - df.ix[df['A'] == value, 'B']
我收到以下警告:
/Users/josh/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/core/indexing.py:415: 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
See the the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
self.obj[item] = s
之前我已经看过这个警告了,我理解了潜在的问题,但为什么我的身体特意引发这个警告呢?据我所知,我正在做一个tipe的任务:
df[<indices>] = <values>
SettingWithoutCopy warning在熊猫中是众所周知的,但据我了解,我已经在使用单级索引(ix
)而不是嵌套索引器(例如[][]
为什么我会收到这个警告,我该如何避免呢?
这是:
INSTALLED VERSIONS
------------------
commit: None
python: 3.4.2.final.0
python-bits: 64
OS: Darwin
OS-release: 13.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.15.0
nose: 1.3.4
Cython: 0.21
numpy: 1.9.1
scipy: 0.14.0
statsmodels: 0.5.0
IPython: 2.2.0
sphinx: 1.2.3
patsy: 0.3.0
dateutil: 2.1
pytz: 2014.7
bottleneck: None
tables: 3.1.1
numexpr: 2.3.1
matplotlib: 1.4.0
openpyxl: 1.8.5
xlrd: 0.9.3
xlwt: None
xlsxwriter: 0.5.7
lxml: 3.4.0
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
rpy2: None
sqlalchemy: 0.9.7
pymysql: None
psycopg2: 2.5.4 (dt dec pq3 ext)