0

I would like to go over an excel file with different stock symbols. How can I check after reading the stocks values (Open,Close,High,Low,Volume) in a dataframe with yahoo, if the dataframe is empty? In this excel list are more than 700 Symbols and some times yahoo have no data for some symbols. So I would like to exclude this symbols, when I go to the loop.

I am struggling with the following code: if df.empty = True: print (stock).

yf.pdr_override()
start = dt.datetime(2020,6,1)
now = dt.datetime.now()

stocklist = pd.read_csv('symbols/Input_ETF_alle_test.csv') 

# stocklist = stocklist.head()
for i in stocklist.index:
 stock = str(stocklist['Symbol'][i]) 
 print (stock)

 df = yf.download(stock,start,now)
 if df.empty = True:
     print (stock)
1
  • 1
    Equality checks are done with ==, not =. You could just use if df.empty:, though. Commented Jan 24, 2021 at 15:39

2 Answers 2

3

You need to change the if to:

if df.empty == True:

or

if df.empty:
Sign up to request clarification or add additional context in comments.

Comments

0

You can use regular expression. it will be good if you elaborate, what you want to exclude!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.