Python - How To Avoid Error (exceptions) In Pandas While Still Getting Data ?
I'm currently using Pandas to get options data from yahoo. It works fine until there is a stock that does not have options, at which point the program crashes. I attempted to creat
Solution 1:
You can handle the RemoteDataError
exception imported from pandas_datareader._utils
:
from pandas_datareader._utils import RemoteDataError
from pandas_datareader.data import Options
tickers = ['GHC']
for i in tickers:
try:
option = Options(i, 'yahoo')
data = option.get_all_data()
except RemoteDataError:
print("No information for ticker '%s'" % i)
continue
Solution 2:
for i in tickers:
try:
option = Options(i,'yahoo')
data = option.get_all_data()
except RemoteDataError: # Add here correct expectation type...
continue # What to do with 'i' and 'data', nulls?
Post a Comment for "Python - How To Avoid Error (exceptions) In Pandas While Still Getting Data ?"