我的数据如下所示;
'userID' 'songID' 'rating'
0 0 7171 5
1 0 8637 4
2 0 21966 4
3 0 35821 5
4 0 82446 5
以下是我的代码,用于创建数据透视表:
ratings = pd.pivot_table(data,
index="userID",
columns="songID",
values="rating")
我遇到了一个 KeyError:'rating'
的问题。
我查看了其他答案,大部分建议使用 .reset_index()
,但这并没有解决我的问题。我一直得到同样的错误。
有什么建议可以解决这个问题吗?
提前感谢。
KeyError
means there is no columnrating
, test it byprint (data.columns.tolist())
- jezrael