英文:
'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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论