0

When I run the following code with a list of tickers, I get an error:

pdr.get_data_yahoo(ticker, '2008-01-01')

KeyError: 'Date'

Is there a way to skip the ticker that caused this error and move to the next ticker, WITHOUT using for loop?

Thanks in advance!

AMC
  • 2,642
  • 7
  • 13
  • 35
thdwjdxor
  • 1
  • 1
  • 3
    Right now, we don't know the structure of your code. Please provide a [minimum reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). If you have multiple `tickers`, I'm not sure how you have achieved this without a loop... – dspencer Mar 25 '20 at 03:19

1 Answers1

0

use this:

try:
  pdr.get_data_yahoo(ticker, '2008-01-01')
except:
  pass

Having said that it is not recommended that you use 'pass' which ignores ALL errors completely...you should use something like this:

except ErrorWithCode as e: print("Received error with code:", e.code) pass

to only ignore the error that you know its cause.

Chadee Fouad
  • 2,630
  • 2
  • 23
  • 29
  • `except: pass` is almost never the right thing to do, see https://stackoverflow.com/questions/54948548/what-is-wrong-with-using-a-bare-except. – AMC Mar 25 '20 at 17:38
  • I agree...that was a quick answer but I was just trying to provide error handling mechanism that he can look further into – Chadee Fouad Mar 26 '20 at 02:50
  • While this may answer the question, it was flagged for review. Answers with no explanation are often considered low-quality. Please provide some commentary for why this is the correct answer. – Dan Mar 26 '20 at 03:34