Query in public database

0

I need to query in an online database, and transform the returned data into a data frame.

I used an existing example on the database website, but I have no idea how to turn it into a database.

The example looks like this sample:

import urllib
url = 'http://dados.cvm.gov.br/api/action/datastore_search?resource_id=92741280-58fc-446b-b436-931faaca4fb4&limit=5&q=_id:01'
fileobj = urllib.request.urlopen(url)
read_file = fileobj.read()
print (read_file)

And as a result, I got this:

  

b '{"help":   " link ",   "success": true, "result": {"resource_id":   "92741280-58fc-446b-b436-931faaca4fb4", "fields": [{"type": "int4",   "id": "_id"}, {"type": "text", "id": "CNPJ_FUNDO"}, {"type":   "timestamp", "id": "DT_COMPTC"}, {"type": "numeric", "id":   "VL_TOTAL"}, {"type": "numeric", "id": "VL_QUOTA"}, {"type":   "numeric", "id": "VL_PATRIM_LIQ"}, {"type": "numeric", "id":   "CAPTC_DIA"}, {"type": "numeric", "id": "RESG_DIA"}, {"type":   "numeric", "id": "NR_COTST"}, {"type": "int8", "id": "_full_count"},   {"type": "float4", "id": "rank"}], "q": "_id = 01", "records": [],   "_links": {"start":   "/ api / action / datastore_search? q = _id% 3D01 & limit = 5 & resource_id = 92741280-58fc-446b-b436-931faaca4fb4"   "next":   "/ api / action / datastore_search? q = _id% 3D01 & offset = 5 & limit = 5 & resource_id = 92741280-58fc-446b-b436-931faaca4fb4"},   "limit": 5}} '

How can I turn this result into a dataframe?

Source Website: link

If it is useful, from what I read on the source website, the data is made available using CKAN.

    
asked by anonymous 31.07.2017 / 15:24

1 answer

0
If you see a dataframe as a table and as a dictionary in Python you will realize that what you have as data, as you have shown, is a set of tables, or a table of tables. Therefore, unless you want to represent this data as a table with dictionaries inside - which is not very useful - you need to define which tables you would like to extract from that table. tables, and how to divide and organize them. With this planning in mind, you can create a script to access the dictionaries or tables of each part of that code, and for each of them, create an appropriate dataframe . Pandas allow you to create a dataframe from a dictionary in Python easily using Pandas.DataFrame(seu_dictionary) .

    
15.09.2017 / 11:18