对熊猫的SettingWithCopyWarning

时间:2018-10-01 20:40:24

标签: python pandas dataframe warnings

res2.loc[: , other_column_name] = res2.loc[: , other_column_name].apply(np.log) 

其中res2pandas.DataFrame,给出以下警告:

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

经过几次尝试,我可以通过将行重写为此内容来摆脱警告

res3 = res2.copy()
log = res2.loc[: , other_column_name].apply(np.log) 
res3.loc[: , other_column_name] = log

这显然不是一个很好的解决方案,有没有更好的方法来解决这个问题?

编辑1

res2的创建方式如下:

res2 = res1[res1.index <= last_valid_sentiment]

res2.head()

        sentiment  inf_neg
2001-11-28  -2.856371      0.534482
2001-12-26  -2.023266      0.473392
2002-01-30  -1.505361      0.444845
2002-02-27  -2.121079      0.433922
2002-03-27  -1.692547      0.469621

0 个答案:

没有答案
相关问题