{ "cells": [ { "cell_type": "markdown", "id": "4d01dff6", "metadata": {}, "source": [ "# Exploring Financial Data using Nasdaq Data Link API" ] }, { "cell_type": "code", "execution_count": 1, "id": "c4812aa8", "metadata": {}, "outputs": [], "source": [ "#importing necessary libraries together with the config.py file\n", "\n", "import requests\n", "import json\n", "import pandas as pd\n", "import config\n", "\n", "# configuring the api_key\n", "api_key = config.api_key\n", "\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "c50a8328", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'datatable': {'data': [[2438, 1868192544, -1802, 10.481948, '2011-06-30', 'Q2', 'U', 'EUR', 'True', 'Deutsche Bank AG', 'Deutsche Bank AG', 'Active', 'DEU', 'Europe', 1159508, '5.1.1', 'DB', 'NYS', 'Taunusanlage 12', None, None, None, 'Frankfurt am Main', None, 'DEU', '60325', '(49) 69 910 00', '(49) 69 910 34 225', 'www.db.com', '2022-12-31', 'Accrued Expenses Turnover', 'Derived'], [2438, 1868216112, -1802, 8.161754, '2011-09-30', 'Q3', 'U', 'EUR', 'True', 'Deutsche Bank AG', 'Deutsche Bank AG', 'Active', 'DEU', 'Europe', 1159508, '5.1.1', 'DB', 'NYS', 'Taunusanlage 12', None, None, None, 'Frankfurt am Main', None, 'DEU', '60325', '(49) 69 910 00', '(49) 69 910 34 225', 'www.db.com', '2022-12-31', 'Accrued Expenses Turnover', 'Derived'], [2438, 1885063456, -1802, 10.788213, '2012-06-30', 'Q2', 'U', 'EUR', 'True', 'Deutsche Bank AG', 'Deutsche Bank AG', 'Active', 'DEU', 'Europe', 1159508, '5.1.1', 'DB', 'NYS', 'Taunusanlage 12', None, None, None, 'Frankfurt am Main', None, 'DEU', '60325', '(49) 69 910 00', '(49) 69 910 34 225', 'www.db.com', '2022-12-31', 'Accrued Expenses Turnover', 'Derived'], [2438, 1885087024, -1802, 9.437545, '2012-09-30', 'Q3', 'U', 'EUR', 'True', 'Deutsche Bank AG', 'Deutsche Bank AG', 'Active', 'DEU', 'Europe', 1159508, '5.1.1', 'DB', 'NYS', 'Taunusanlage 12', None, None, None, 'Frankfurt am Main', None, 'DEU', '60325', '(49) 69 910 00', '(49) 69 910 34 225', 'www.db.com', '2022-12-31', 'Accrued Expenses Turnover', 'Derived'], [2438, 1901934112, -1802, 8.755041, '2013-06-30', 'Q2', 'U', 'EUR', 'True', 'Deutsche Bank AG', 'Deutsche Bank AG', 'Active', 'DEU', 'Europe', 1159508, '5.1.1', 'DB', 'NYS', 'Taunusanlage 12', None, None, None, 'Frankfurt am Main', None, 'DEU', '60325', '(49) 69 910 00', '(49) 69 910 34 225', 'www.db.com', '2022-12-31', 'Accrued Expenses Turnover', 'Derived'], [2438, 1901957680, -1802, 8.109493, '2013-09-30', 'Q3', 'U', 'EUR', 'True', 'Deutsche Bank AG', 'Deutsche Bank AG', 'Active', 'DEU', 'Europe', 1159508, '5.1.1', 'DB', 'NYS', 'Taunusanlage 12', None, None, None, 'Frankfurt am Main', None, 'DEU', '60325', '(49) 69 910 00', '(49) 69 910 34 225', 'www.db.com', '2022-12-31', 'Accrued Expenses Turnover', 'Derived'], [2438, 1901981184, -7562, 7.047783, '2013-12-31', 'A', 'N', 'EUR', 'True', 'Deutsche Bank AG', 'Deutsche Bank AG', 'Active', 'DEU', 'Europe', 1159508, '5.1.1', 'DB', 'NYS', 'Taunusanlage 12', None, None, None, 'Frankfurt am Main', None, 'DEU', '60325', '(49) 69 910 00', '(49) 69 910 34 225', 'www.db.com', '2022-12-31', 'Cash Flow Per Share', 'Cash Flow'], [17630, 1851369024, -4524, 161000000.0, '2010-12-31', 'Q4', 'N', 'CAD', 'True', 'BCE Inc', 'BCE Inc', 'Active', 'CAN', 'North America', 718940, '6.1.2', 'BCE', 'NYS', '1 Carrefour Alexander-Graham-Bell', 'Building A', '8th Floor', None, 'Verdun', 'Quebec', 'CAN', 'H3E 3B3', '800 339-6353', '514 786-3970', 'www.bce.ca', '2022-12-31', 'Operating Income', 'Income Statement'], [17630, 1851369024, -5917, 3.440906, '2010-12-31', 'Q4', 'N', 'CAD', 'True', 'BCE Inc', 'BCE Inc', 'Active', 'CAN', 'North America', 718940, '6.1.2', 'BCE', 'NYS', '1 Carrefour Alexander-Graham-Bell', 'Building A', '8th Floor', None, 'Verdun', 'Quebec', 'CAN', 'H3E 3B3', '800 339-6353', '514 786-3970', 'www.bce.ca', '2022-12-31', 'Operating Margin', 'Derived'], [17630, 1868192544, -1016, 2.631808, '2011-06-30', 'Q2', 'U', 'CAD', 'True', 'BCE Inc', 'BCE Inc', 'Active', 'CAN', 'North America', 718940, '6.1.2', 'BCE', 'NYS', '1 Carrefour Alexander-Graham-Bell', 'Building A', '8th Floor', None, 'Verdun', 'Quebec', 'CAN', 'H3E 3B3', '800 339-6353', '514 786-3970', 'www.bce.ca', '2022-12-31', 'Interest Coverage', 'Derived']], 'columns': [{'name': 'compnumber', 'type': 'Integer'}, {'name': 'reportid', 'type': 'Integer'}, {'name': 'mapcode', 'type': 'Integer'}, {'name': 'amount', 'type': 'BigDecimal(36,14)'}, {'name': 'reportdate', 'type': 'Date'}, {'name': 'reporttype', 'type': 'String'}, {'name': 'auditorstatus', 'type': 'String'}, {'name': 'currency', 'type': 'String'}, {'name': 'consolidated', 'type': 'String'}, {'name': 'longname', 'type': 'String'}, {'name': 'shortname', 'type': 'String'}, {'name': 'status', 'type': 'String'}, {'name': 'countrycode', 'type': 'String'}, {'name': 'region', 'type': 'String'}, {'name': 'cik', 'type': 'Integer'}, {'name': 'mic', 'type': 'String'}, {'name': 'ticker', 'type': 'String'}, {'name': 'exchange', 'type': 'String'}, {'name': 'address1', 'type': 'String'}, {'name': 'address2', 'type': 'String'}, {'name': 'address3', 'type': 'String'}, {'name': 'address4', 'type': 'String'}, {'name': 'city', 'type': 'String'}, {'name': 'statecode', 'type': 'String'}, {'name': 'country', 'type': 'String'}, {'name': 'zipcode', 'type': 'String'}, {'name': 'phonenumber', 'type': 'String'}, {'name': 'faxnumber', 'type': 'String'}, {'name': 'website', 'type': 'String'}, {'name': 'fye', 'type': 'Date'}, {'name': 'indicator', 'type': 'String'}, {'name': 'statement', 'type': 'String'}]}, 'meta': {'next_cursor_id': 'djFfMTAyNTkwN18xNzA3NDk1ODgz'}}\n" ] } ], "source": [ "# base url\n", "\n", "api_url='https://data.nasdaq.com/api/v3/datatables/MER/F1.json'\n", "\n", "# our `parameters` dictionary\n", "\n", "parameters = {\n", " 'api_key': api_key,\n", " 'qopts.per_page': 10 # Number of rows to fetch\n", "\n", "}\n", "\n", "# Fetching the data and converting it to json\n", "\n", "json_data=requests.get(api_url, params=parameters).json()\n", "\n", "# printing the json data\n", "\n", "print(json_data)\n", "\n" ] }, { "cell_type": "markdown", "id": "1c33a382", "metadata": {}, "source": [ "## Processing the JSON Data into a DataFrame" ] }, { "cell_type": "code", "execution_count": 3, "id": "bf538a46", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | compnumber | \n", "reportid | \n", "mapcode | \n", "amount | \n", "reportdate | \n", "reporttype | \n", "auditorstatus | \n", "currency | \n", "consolidated | \n", "longname | \n", "... | \n", "city | \n", "statecode | \n", "country | \n", "zipcode | \n", "phonenumber | \n", "faxnumber | \n", "website | \n", "fye | \n", "indicator | \n", "statement | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "2438 | \n", "1868192544 | \n", "-1802 | \n", "10.481948 | \n", "2011-06-30 | \n", "Q2 | \n", "U | \n", "EUR | \n", "True | \n", "Deutsche Bank AG | \n", "... | \n", "Frankfurt am Main | \n", "None | \n", "DEU | \n", "60325 | \n", "(49) 69 910 00 | \n", "(49) 69 910 34 225 | \n", "www.db.com | \n", "2022-12-31 | \n", "Accrued Expenses Turnover | \n", "Derived | \n", "
1 | \n", "2438 | \n", "1868216112 | \n", "-1802 | \n", "8.161754 | \n", "2011-09-30 | \n", "Q3 | \n", "U | \n", "EUR | \n", "True | \n", "Deutsche Bank AG | \n", "... | \n", "Frankfurt am Main | \n", "None | \n", "DEU | \n", "60325 | \n", "(49) 69 910 00 | \n", "(49) 69 910 34 225 | \n", "www.db.com | \n", "2022-12-31 | \n", "Accrued Expenses Turnover | \n", "Derived | \n", "
2 | \n", "2438 | \n", "1885063456 | \n", "-1802 | \n", "10.788213 | \n", "2012-06-30 | \n", "Q2 | \n", "U | \n", "EUR | \n", "True | \n", "Deutsche Bank AG | \n", "... | \n", "Frankfurt am Main | \n", "None | \n", "DEU | \n", "60325 | \n", "(49) 69 910 00 | \n", "(49) 69 910 34 225 | \n", "www.db.com | \n", "2022-12-31 | \n", "Accrued Expenses Turnover | \n", "Derived | \n", "
3 | \n", "2438 | \n", "1885087024 | \n", "-1802 | \n", "9.437545 | \n", "2012-09-30 | \n", "Q3 | \n", "U | \n", "EUR | \n", "True | \n", "Deutsche Bank AG | \n", "... | \n", "Frankfurt am Main | \n", "None | \n", "DEU | \n", "60325 | \n", "(49) 69 910 00 | \n", "(49) 69 910 34 225 | \n", "www.db.com | \n", "2022-12-31 | \n", "Accrued Expenses Turnover | \n", "Derived | \n", "
4 | \n", "2438 | \n", "1901934112 | \n", "-1802 | \n", "8.755041 | \n", "2013-06-30 | \n", "Q2 | \n", "U | \n", "EUR | \n", "True | \n", "Deutsche Bank AG | \n", "... | \n", "Frankfurt am Main | \n", "None | \n", "DEU | \n", "60325 | \n", "(49) 69 910 00 | \n", "(49) 69 910 34 225 | \n", "www.db.com | \n", "2022-12-31 | \n", "Accrued Expenses Turnover | \n", "Derived | \n", "
5 rows × 32 columns
\n", "