I am trying to get stock market data from Yahoo. I have no problem getting stock price and dividends, but once splits are involved I get errors.
example the "coca cola" stock ('KO')
from pandas_datareader import data
start_date = '2000-01-01'
end_date = '2020-12-31'
a = data.DataReader('KO', 'yahoo-actions', start_date, end_date)
I get a error (i think referring to a 2:1 stock split):
File "<string>", line 1
2:1
^
SyntaxError: invalid syntax
If I run the same code on a stock with no splits (i.e. 'TSLA') it runs without a problem. I tried making it in to a string but without success.
I am out of ideas and couldn't find a similar question online. does any one have a idea what might be wrong?
SOLVED:
In file 'daily.py' in the 'pandas_datareader' lib I changed:
if "SPLIT" in types:
def split_ratio(row):
if float(row["Numerator"]) > 0:
return eval(row["Splitratio"])
else:
return 1
to:
if "SPLIT" in types:
def split_ratio(row):
if float(row["Numerator"]) > 0:
return row["Splitratio"]
else:
return 1
now it works locally but i cant use it on colab.
good enough for now.