I would like to filter my data so that I only get the symbol, close and sector.
I tried using the code below but I get an error that 'list is not callable' .
Also, do note that iexfinance uses filter_, as filter is a reserved word in Python
print(losers(filter_=['symbol','close']))
Any help will be appreciated. Thanks guys!
You get a list from get_market_losers()
that you need to iterate over:
for loser in losers:
print(loser["close"], loser["symbol"], loser["sector"])
Printout:
9.1 NEWA Industrials
4.75 LCI Healthcare
2.3 SN Energy
8.51 SWZ Financial Services
2.95 PES Energy
8.1 EGAN Technology
8.58 CIFS Financial Services
1.76 GERN Healthcare
1.03 BW Technology
6.18 JILL Consumer Cyclical
To get all your data in a dataframe use this (the columns are already named according to the IEX features):
df = pd.DataFrame(losers)
# printout transposed so that you see the long list of features
df.head(1).T
Printout:
avgTotalVolume 543967
calculationPrice close
change -0.36
changePercent -0.03805
...
Filter from the dataframe directly:
df.loc[:, ["close", "symbol", "sector"]]
Printout: