python - 大熊猫上的 SettingWithCopyWarning
问题描述
线
res2.loc[: , other_column_name] = res2.loc[: , other_column_name].apply(np.log)
, where res2
is a pandas.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
解决方案
推荐阅读
- javascript - 承诺链
- python-3.x - TinyDb 在执行更新时缓存数据,但从不更新 json 文档
- flutter - CupertinoIndicator for refreshindicator Flutter
- javascript - 如何在 Mongo 查询中传递变量,例如 /variable/?
- c++ - 将 AT 命令字符串解析为整数
- reactjs - React.js - 无法将 DataRows 显示到 TBody
- sql - 从数据库更新 webclient 响应
- wordpress - elementor中用于发布/自定义发布的多个模板
- reactjs - 材料 UI 开关输入未在表单重置时更新
- c++ - OpenMP 减少:min 给出不正确的结果