Skip to content
Advertisement

How to import API data using Pandas?

I am trying to pull some data from EIA API, below is what I tried but I’m getting the error on the first line of code:

AttributeError: ‘str’ object has no attribute ‘text’

Any help would be much appreciated!

JavaScript

Advertisement

Answer

You haven’t requested anything from the API. Look carefully at your first line:

JavaScript

There are 2 = signs, so what you’re really doing is assigning the URL string to both your call_eia variable and the get attribute of the requests module, overwriting the function that was there originally. Then, when you try to pass call_eia to pd.read_csv(), instead of passing a requests object, you’re just passing a string, the URL.

Try

JavaScript

instead and your code should work.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement