0

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.

toyota Supra
  • 3,181
  • 4
  • 15
  • 19
Lethabo
  • 3
  • 3

1 Answers1

0

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.