I am watching this tutorial where I am trying to use iexfinance to get stock data. You have the option to choose the data type when requesting the data, I chose "pandas". When I run the built-in function I get an error that reads AttributeError: module 'pandas.compat' has no attribute 'string_types'
I am using python 3.7. I have uninstalled and reinstalled both iexfinance and pandas. I also created and IEX cloud account and passed in a secret key like the documentation states, but the same error. The tutorial doesn't mention any of these steps and its confusing why his works and mine isn't.
I have tried to make the code simpler by following examples on the website: Even when running:
from iexfinance.stocks import Stock
df = Stock("AAPL", output_format="pandas")
print(df.get_quote().head())
The error persists
The expected output is:
AAPL
avgTotalVolume 30578248
calculationPrice close
change -0.58
changePercent -0.00298
close 207.27
The output I am receiving is:
Traceback (most recent call last):
File "app.py", line 18, in <module>
df = Stock("AAPL", output_format="pandas")
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/iexfinance/stocks/base.py", line 45, in __init__
self.symbols = list(map(lambda x: x.upper(), _handle_lists(symbols)))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/iexfinance/utils/__init__.py", line 43, in _handle_lists
if isinstance(l, (compat.string_types, int)):
AttributeError: module 'pandas.compat' has no attribute 'string_types'
You can try reverting the pandas version to 0.24.2 as a workaround:
pip install pandas==0.24.2
At this point I am still not sure if a bug in pandas or something else.
EDIT: Probably the iexfinance is using some internals in Pandas, and pandas has undergone a major change dropping python 2 and all the compatibility code.
This is also already on their issue tracker: https://github.com/addisonlynch/iexfinance/issues/163
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With