I am using pyfolio for performance metrics but showing below error

I am using pyfolio for performance metrics but showing below error



 File "C:\Users\shiri\anaconda3\lib\site-packages\pyfolio\plotting.py", line 595, in show_perf_stats

    date_rows['Start date'] = returns.index[0].strftime('%Y-%m-%d')

AttributeError: 'str' object has no attribute 'strftime'




 


import pandas as pd
import numpy as np
import talib as ta
import pyfolio as pf



#---------------------- Stock data reading ---------------------#
columns = ['index','Date','Open','High','Low','Close','Volume','OI']
df = pd.read_csv(r'D:/Algorithmic Trading Proejct/Project/stock_data/downloaded_data/nifty_bank_10minute.txt', names=columns, index_col='Date')
df.drop(['index','Volume','OI'], axis=1, inplace=True)
data = pd.DataFrame(df)

#---------------------- Stock data Returns ---------------------#
df['returns'] = (df['Close']/df['Close'].shift(1)) -1

stock_rets = df['returns']

pf.create_returns_tear_sheet(stock_rets, live_start_date='2018-06-01')

output of data

Date
2018-06-01T09:15:00+0530         NaN
2018-06-01T09:25:00+0530   -0.002087
2018-06-01T09:35:00+0530    0.001123
2018-06-01T09:45:00+0530    0.001741
2018-06-01T09:55:00+0530    0.001974

Hi Shirish, 



This error occurs when we try to call the strftime() method on a string instead of a datetime object. To solve this error, you need to convert the string to datetime object before calling strftime() method. 



You can also take a look at this for reference. 



Hope this helps!



Thanks,

Bhavika

Thanks … i already solved the problem  using  df['Date'] = pd.to_datetime(df.index), now it working for me