python - Alpha Vantage (Yahoo Fin alt) & Pandas Dataframe Issue - .days -


looking alternatives yahoo finance seems it's gone good. came across alpha vantage looks interesting. code below running until try find delta between start , end date, error below:

from alpha_vantage.timeseries import timeseries ts = timeseries(key=key, output_format="pandas") data, meta_data = ts.get_daily("aapl",outputsize="full") days = (data.index[-1]- data.index[0]).days 

output:

days = (data.index[-1]- data.index[0]).days typeerror: unsupported operand type(s) -: 'str' , 'str' 

i've tried:

days = (float(data.index[-1])- float(data.index[0])).days 

and

days = (int(data.index[-1])- int(data.index[0])).days 

printed dataframe head asked below

print(data.head()) 

output:

             open     low   close    high     volume 2000-01-03  104.87  101.69  111.94  112.50  4783900.0 2000-01-04  108.25  101.19  102.50  110.62  4574800.0 2000-01-05  103.75  103.00  104.00  110.56  6949300.0 2000-01-06  106.12   95.00   95.00  107.00  6856900.0 2000-01-07   96.50   95.50   99.50  101.00  4113700.0 

no luck anything, appreciated!

it's clear index string. convert datetime using df.index.astype:

in [1165]: df.index = df.index.astype(np.datetime64) 

now, you're doing work:

in [1166]: (df.index[-1] - df.index[0]).days out[1166]: 4 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -