‘Series’对象没有’corrwith’属性。

huangapple go评论54阅读模式
英文:

'Series' object has no attribute 'corrwith'

问题

corr15=log_returns15.corrwith(market_log_returns15)

AttributeError Traceback (most recent call last)
/var/folders/9x/1gr05h793pv19rtskjk5ljj40000gn/T/ipykernel_775/2632475604.py in
----> 1 corr15=log_returns15.corrwith(market_log_returns15)

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/generic.py in getattr(self, name)
5485 ):
5486 return self[name]
-> 5487 return object.getattribute(self, name)
5488
5489 def setattr(self, name: str, value) -> None:

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

我尝试将这两个返回值重命名为相同的名称,但仍然没有效果。

英文:

How do I fix this error?

corr15=log_returns15.corrwith(market_log_returns15)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/9x/1gr05h793pv19rtskjk5ljj40000gn/T/ipykernel_775/2632475604.py in <module>
----> 1 corr15=log_returns15.corrwith(market_log_returns15)

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5485         ):
   5486             return self[name]
-> 5487         return object.__getattribute__(self, name)
   5488 
   5489     def __setattr__(self, name: str, value) -> None:

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

I tried renaming the two returns to the same name, but it is still not working.

答案1

得分: 0

从你的错误信息来看,log_returns15 是一个 Pandas Series,它具有用于计算相关性的 [corr](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.corr.html) 方法。[corrwith](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.corrwith.html) 是一个 Pandas DataFrame 方法,不能在 Series 对象上调用。

所以,要么使用 corr,要么log_returns15 转换为 DataFrame

英文:

from your error it looks like log_returns15 is a Pandas Series, which has a [corr](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.corr.html) method for correlations. [corrwith](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.corrwith.html) is a Pandas DataFrame method, which can not be called on a Series object.

So, either use corr or make log_returns15 a DataFrame.

huangapple
  • 本文由 发表于 2023年6月26日 23:04:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76557922.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定