3

When I run the following statement on a dataframe with two columns and numerical values:

df.ix[df['A'] == value, 'B'] = 3600 - df.ix[df['A'] == value, 'B']

I get the following warning:

/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

I have seen this warning before, and I understand the underlying problem, but why does my statament specifically trigger this warning? As far as I can tell, I am doing an assignment of the tipe:

df[<indices>] = <values>

The SettingWithoutCopy warning is well-known in pandas, but as far as I understand, I am already using a single-level indexing (ix) and not nesting indexers (e.g. [][]. Why do I get this warning, and how can I avoid it?

This is with:

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)
Community
  • 1
  • 1
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564

0 Answers0