For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
A confused question about Pandas DataFeed
-
Hi, maybe it is very basic, but I am glad that some one cloud give some tips about it:
when I load the
orcl-1995-2014.txt
from github datas with command:class PandasData(feed.DataBase): params = ( ('datetime', None), # here I use "None" to indicate the index of dataframe is datetime ('open', 'Open'), ('high', 'High'), ('low', 'Low'), ('close', 'Close'), ('volume', 'Volume'), ('openinterest', None), ) df = pd.read_csv('orcl-1995-2014.txt', skiprows=0, header=0, parse_dates=True, index_col='Date') data = bt.feeds.PandasData(dataname=df) # ... and go on .... cerebro.run( )
in this case above, everything runs well, but if I make a little different from the example code, as below:
class PandasData(feed.DataBase): params = ( ('datetime', "Date"), # here I use "Date" to indicate the "Date" column is datetime ('open', 'Open'), ('high', 'High'), ('low', 'Low'), ('close', 'Close'), ('volume', 'Volume'), ('openinterest', None), ) df = pd.read_csv('orcl-1995-2014.txt', skiprows=0, header=0, parse_dates=True) # remove index_col='Date' data = bt.feeds.PandasData(dataname=df) # ... and go on .... cerebro.run( )
I make those little change follow the docs, but then, I got this
error
:266 267 # convert to float via datetime and store it --> 268 dt = tstamp.to_pydatetime() 269 dtnum = date2num(dt) 270 self.lines.datetime[0] = dtnum AttributeError: 'int' object has no attribute 'to_pydatetime'
It is very confused for me, It seems the docs maybe out of date or misunderstood?
-
@life said in A confused question about Pandas DataFeed:
df = pd.read_csv('orcl-1995-2014.txt',
skiprows=0,
header=0,
parse_dates=True) # remove index_col='Date'I the second instance tell pandas where to parse dates:
dataframe = pd.read_csv(datapath, header=0, parse_dates=["Date"], index_col=None) data = bt.feeds.PandasData( dataname=dataframe, datetime="Date", open='Open', high='High', low='Low', close='Close', volume='Volume', openinterest=None )