【问题标题】:how to fix 'Series' object has no attribute 'reshape' in jypterLab如何修复“系列”对象在 jupyterLab 中没有“重塑”属性
【发布时间】:2020-02-07 14:41:07
【问题描述】:

This is my code for the music recommendatin system.

这是错误,。

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-19-b58e57e00aac> in <module>
      2 print (query_index)
      3 
----> 4 distances, indices = model_knn.kneighbors(wide_artist_data.iloc[query_index, :].reshape(1, -1), n_neighbors = 6)
      5 
      6 for i in range(0, len(distances.flatten())):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   5272             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5273                 return self[name]
-> 5274             return object.__getattribute__(self, name)
   5275 
   5276     def __setattr__(self, name: str, value) -> None:

AttributeError: 'Series' object has no attribute 'reshape'

【问题讨论】:

  • 嗨,Devilsubarna!欢迎来到 StackOverflow!下次,请复制并粘贴您的代码,而不是发送链接(这有助于我们为您测试)

标签: python attributeerror recommendation-engine


【解决方案1】:
AttributeError: 'Series' object has no attribute 'reshape'

pandas.Series.reshape 文档说:

自 0.19.0 版后已弃用:调用此方法将引发错误。请打电话 .values.reshape(...) 代替。

所以应该是wide_artist_data.iloc[query_index, :].values.reshape(1, -1)

【讨论】:

    猜你喜欢
    • 2019-05-12
    • 2019-07-06
    • 2018-06-06
    • 2015-06-08
    • 1970-01-01
    • 2020-11-29
    • 2018-06-20
    • 2019-12-08
    • 2019-12-30
    相关资源
    最近更新 更多