我在pandas python中得到SettingWithCopyWarning
。这是我的代码。
def get_priority(x):
if x['src_id'] is "":
return 99
elif x['priority'] is "":
return 98
else:
return x['priority']
Admits_Prelim1['priority'] = Admits_Prelim1.apply(get_priority, axis=1)
当我这样执行时,它会抛出SettingWithCopyWarning
警告。所以,我改变了这样。
Admits_Prelim1.loc[Admits_Prelim1['src_prov_id'] == "", 'priority'] = 99
Admits_Prelim1.loc[Admits_Prelim1['priority'] == "", 'priority'] = 98
Admits_Prelim1.loc[((Admits_Prelim1['priority'] != 98) & (Admits_Prelim1['priority'] != 99)), 'priority'] = Admits_Prelim1['priority']
这是我得到的确切信息。
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[key] = _infer_fill_value(value)
/mapr/datalake/anaconda2/lib/python2.7/site-packages/pandas/core/indexing.py:465: 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] = s
我仍然面临着这些问题。我怎么了?有人可以帮助我吗?谢谢。