我正在使用表单的图书评级数据集
userID | ISBN | Rating
23413 1232 2.5
12321 2311 3.2
23413 2532 1.7
23413 7853 3.8
现在我需要添加第四列,其中包含每个用户在整个数据集中的评分数:
userID | ISBN | Rating | Ratings_per_user
23413 1232 2.5 3
12321 2311 3.2 1
23413 2532 1.7 3
23413 7853 3.8 3
我努力了:
df_new['Ratings_per_user'] = df_new['userID'].value_counts()
但我收到一个错误:
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
并且整个新列都填充了NaN.
慕码人2483693
手掌心
ibeautiful
相关分类