0

Can someone please explain why the following straight forward lines:

nbrs['d_inv'] = nbrs['d'].pow(-1)
...
nbrs[k] = nbrs[c] * nbrs['d_inv']

(k and c are keys) each raise a SettingWithCopyWarning:

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 caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

when I try to replicate this behavior in iPython:

import pandas as pd
import numpy.random as rand

t = pd.DataFrame()
t['d'] = rand.uniform(0,1,5)
t['d_inv'] = t.pow(-1)
t['sum'] = t['d'] + t['d_inv']

No warning is raised. What's going on here?

[edit 1] I'm not trying do chained indexing. I'm just trying to populate an empty column.

[edit 2]

nbrs = pd.DataFrame(row_generator()) wherein each row is Series:

=====  =====  =====  =====
name = None
--------------------------
lat    lon    head   d
=====  =====  =====  =====
float  float  float  float
=====  =====  =====  =====

[edit 3] NOT A DUPLICATE

waring message becomes even less specific

using nbrs.loc[:,'d_inv'] = nbrs['d'].pow(-1) raises

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 caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
self.obj[item_labels[indexer[info_axis]]] = value
Sean McVeigh
  • 569
  • 3
  • 18

0 Answers0