如何在熊猫数据框Python中的str.replace和str.split中修复SettingWithCopyWarnings?

时间:2019-08-14 06:44:09

标签: python pandas dataframe

我收到以下代码的str.replace和str.split警告

df['Amount'] = df['Amount'].str.replace(')', '')   
df[['Inside','Outside']] = df.Amount.str.split(",",expand=True) 

以下是警告

dynamic_module:222: 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


C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py:3391: 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[k1] = value[k2]

df ['Amount']。loc的使用无济于事,可能使用不正确,正确的方法是什么?

0 个答案:

没有答案