I am looking at the following website: https://data.gov.sg/dataset/bunker-sales-monthly?resource_id=44da3191-6c57-4d4a-8268-8e2c418d4b43 and they have the following example for extracting data using their API:
import requests
result = []
headers = {'User-Agent': 'Mozilla/5.0'}
url = "https://data.gov.sg/api/action/datastore_search?resource_id=44da3191-6c57-4d4a-8268-8e2c418d4b43"
r = requests.get(url, headers=headers)
data = r.json()
print(data)
This produces the following, out of which I want to extract only the 'records' bit out of the output, and into a more readable format. Ideally, I want this data in a pandas data frame:
{'records': [{'bunker_type': 'Marine Gas Oil', 'bunker_sales': '135.4', '_id': 1, 'month': '1995-01'}, {'bunker_type': 'Marine Diesel Oil', 'bunker_sales': '67.9', '_id': 2, 'month': '1995-01'}, {'bunker_type': 'Marine Fuel Oil 180 cst', 'bunker_sales': '412.9', '_id': 3, 'month': '1995-01'}, {'bunker_type': 'Marine Fuel Oil 380 cst', 'bunker_sales': '820.3', '_id': 4, 'month': '1995-01'}, {'bunker_type': 'Marine Fuel Oil 500 cst +', 'bunker_sales': '0', '_id': 5, 'month': '1995-01'}...
In the format as below:
df= pd.DataFrame(columns=['month', 'bunker_type', 'bunker_sales'])
How could I go about extracting this data?