I am currently trying to do some calculations with the income statement of GOOGL imported from AlphaVantage's API. Here below is my code:
'company = "GOOG"'
'API = os.getenv('ALPHAVANTAGE_API_KEY')'
'IS = requests.get(f'https://www.alphavantage.co/query?
function=INCOME_STATEMENT&symbol=GOOG&apikey=API').json()'
'IS'
After importing this income statement, I am able to print out the data which comes out as a list. I want to extract
'index[0]'
of this list(most recent annual report) although when I do this I get a
'Key error: 0'
response. What do I do?
CodePudding user response:
IS
is initialized as a JSON:
IS = requests.get(f'https://www.alphavantage.co/query?
function=INCOME_STATEMENT&symbol=GOOG&apikey=API').json()
So it has keys and not indexes like 0. From this example in the API's docs, you can get the most recent annual report (if the annual reports are sorted by descending date! Verify it is so, in the docs!) simply by doing:
IS["annualReports"][0]