【问题标题】:How to find a correlation to a value如何找到与值的相关性
【发布时间】:2019-07-30 05:48:24
【问题描述】:

我有一个图书评级数据集(用户 ID、isbn、电影标题、评级……),我想回答一个问题“如果我喜欢这本书,我可能还会考虑这些……” .

我试图从我的数据集中创建一个数据透视表,但由于未堆叠的数据框太大而导致溢出错误,所以我只是对其进行了分组并尝试使用 corrwith() 如下:

#data_p = pd.pivot_table(data, values='Book-Rating', index='User-ID', columns='ISBN') #This raises an overflow error
data_p = data.groupby(['User-ID', 'Book-Title'])['Book-Rating'].mean().to_frame()
i = int(data.index[data['Book-Title'] == 'The Fellowship of the Ring (The Lord of the Rings, Part 1)'][0])
data_p.corrwith(i)

...引发

AttributeError: 'int' 对象没有属性 '_get_numeric_data'

我也试过了:

data_p.corrwith('The Fellowship of the Ring (The Lord of the Rings, Part 1)')

这会给出与“字符串”对象相同的错误。

我们将不胜感激。

【问题讨论】:

  • corrwith 期望另一个数据帧或系列作为参数,但您传入字符串

标签: python


【解决方案1】:

“相关性”是指两组数之间的差异程度。如果您只有一个数字,则没有任何变化,因此没有什么可比较的。如果您执行i = (data.index[data['Book-Title'] == 'The Fellowship of the Ring (The Lord of the Rings, Part 1)'][0]).apply(int),我希望这会消除当前错误并引发新错误,因为您尝试关联的两件事的大小不同。

获取数据透视表的内存不足对我来说似乎很奇怪,但groupby 不是。我建议你花更多的精力看看你是否能找出这个错误。也许您输入了错误?

【讨论】:

    猜你喜欢
    • 2015-11-09
    • 2011-04-11
    • 2023-03-07
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    相关资源
    最近更新 更多