5

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'

3 Answers 3

7

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

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, that seemed to work. Thank you so much for the advice!
1

The method about: pip install pandas==0.24.2 is right~ try this.

Comments

0

To date 2 October 2019, just update iexfinance to the latest version (0.4.3) and the problem is solved.
Do this:

pip install iexfinance --upgrade

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.