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).
JavaScript
x
15
15
1
yf.pdr_override()
2
start = dt.datetime(2020,6,1)
3
now = dt.datetime.now()
4
5
stocklist = pd.read_csv('symbols/Input_ETF_alle_test.csv')
6
7
# stocklist = stocklist.head()
8
for i in stocklist.index:
9
stock = str(stocklist['Symbol'][i])
10
print (stock)
11
12
df = yf.download(stock,start,now)
13
if df.empty = True:
14
print (stock)
15
Advertisement
Answer
You need to change the if to:
JavaScript
1
2
1
if df.empty == True:
2
or
JavaScript
1
2
1
if df.empty:
2