reason
When using pyfolio
, we encountered the following errors:
/usr/local/lib/python3.7/dist-packages/pyfolio/ timeseries.py in gen_ drawdown_ table(returns, top)
1006 recovery,
1007 freq=‘B’))
-> 1008 df_ drawdowns.loc [i, ‘Peak date’] = ( peak.to_ pydatetime()AttributeError: ‘ numpy.int64 ’ object has no attribute ‘to_ pydatetime’
analysis
Confused, is very confused, after all, the transfer of a problem is also very uncomfortable.
search online, pyfolio
github issues also has many people make complaints about this problem, such as #520
, #652
, #653
, but more people are same error, no solution.
Solution
Many solutions have been found on the Internet. They have tried one by one. Only the last one works well. Everyone can try it
s1 (Failed)
The /usr/local/lib/python3.7/dist-packages/pyfolio/ timeseries.py
893 line changed to
valley = underwater.index[np.argmin(underwater)] # end of the period
It’s no use, continue to change:
s2 (Failed)
The *. To_ Pydatetime()
change to this
pd.to_datetime(peak)
pd.to_datetime(valley
pd.to_datetime(recovery)
Failure, and then repeatedly change those lines of code in the reference websites, mainly for the function that reported the error and def get_ max_ drawdown_ Underwater (underwater):
failed. It’s better to find a solution without changing the code:
the code in
sn (Success)
If we install it in PIP install pyfolio
, then we uninstall and install it in GIT. Maybe it’s the latest version or something. In the end, this is the solution:
!pip uninstall pyfolio # uninstall
!pip install git+https://github.com/quantopian/pyfolio # reinstall
After unloading, restart the code, or del pyfolio
Import pyfolio , it is recommended to restart
and then run it again ~
finally, it’s out of the question:
Read More:
- AttributeError: ‘Tensor‘ object has no attribute ‘_numpy‘
- AttributeError: ‘numpy.ndarray‘ object has no attribute ‘softmax‘
- AttributeError: module ‘numpy‘ has no attribute ‘getbuffer‘
- Attributeerror: object has no attribute
- AttributeError: ‘_io.TextIOWrapper‘ object has no attribute ‘softspace‘
- AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- AttributeError:‘AxesSubplot’object has no attribute‘bar_label’
- Attributeerror: ‘bytes’ object has no attribute’ encode ‘
- python gensim AttributeError: ‘Doc2Vec‘ object has no attribute ‘dv‘
- Attributeerror: ‘dataframe’ object has no attribute ‘IX’ error
- AttributeError: ‘dict‘ object has no attribute ‘iteritems‘
- AttributeError: ‘WebDriver‘ object has no attribute ‘w3c‘
- Solution: attributeerror: type object ‘ioloop’ has no attribute ‘initialized’
- AttributeError: ‘NoneType‘ object has no attribute ‘shape‘
- AttributeError: ‘PipelinedRDD‘ object has no attribute ‘toDF‘
- Python AttributeError: ‘bool‘ object has no attribute ‘ui‘
- [Solved] spacy Install Error: AttributeError: type object ‘_CleanResult‘ has no attribute ‘from_link‘
- AttributeError: ‘Settings’ object has no attribute ‘ROOT_URLCONF’
- Keras Model AttributeError:’str‘ object has no attribute ’call‘
- AttributeError: type object ‘Image‘ has no attribute ‘open‘