pandas - 处理 pandas 的“尝试使用 .iloc”错误
问题描述
我正在计算我的书评数据框中每个用户的评分数,方法是:
df_new['ratings_per_user']=df_new.groupby('userID')['userID'].transform('count')
这似乎可行,但会引发错误(或者更确切地说,是警告):
/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:1: 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
"""Entry point for launching an IPython kernel.
我不明白如何使用 重写上述命令.iloc
,更一般地说,实际问题是什么。
解决方案
推荐阅读
- html - 在 InteliJ 中将 Javadoc 导出为 html
- android - android gradle 3.2.1 到 3.3.1 使用 CDATA 破坏字符串资源
- java - 在 Java 中按列而不是行对 2D 数组进行平面映射
- python - 如何打印数组元素?
- ansible - 运行一个未包含在剧中但属于角色的 ansible 任务
- r - 如何替换 R 矩阵中匹配行名、列名和值的值
- excel - 如何使用 VBA 插入包含数字变量的公式
- angular - 部署在 Kubernetes 入口路径上时无法获得 Angular 7 路由
- java - 播放框架泄漏 jar 文件导致“打开的文件过多”错误
- c++ - 计算闰年 - 表达式必须有一个可修改的左值