-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Closed
Labels
IndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesUsage Question
Description
I'm (consistently) getting a value is trying to be set on a copy of a slice... error on the following bit of code, and can't figure out why:
i['gender'] = i.gender.replace({'male':'m', 'female':'f'})
The full error:
See the the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
"""Sympy configuration"""
/Users/Nick/anaconda/lib/python3.4/site-packages/spyderlib/widgets/externalshell/start_ipython_kernel.py:16: 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
It seems dependent on something about the i DataFrame, but said DataFrame is way to big to include here (143 rows, 43 columns).
When I try and recreate this with a small example dataset, I don't get the error any more:
df = pd.DataFrame({'col1':['a','b','c'], 'col2':[0,1,2]})
df['col1'] = df.col1.replace({'b':'z', 'c':'z'})
Does anyone have any idea why this is happening?
Metadata
Metadata
Assignees
Labels
IndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesUsage Question