Skip to main content

A Python API-wrapper for Government of India’s Open Government Data OGD platform

Project description

datagovindia

MIT license

A Python API-wrapper for Government of India’s Open Government Data OGD platform

datagovindia is an API wrapper for the over 80,000 APIs available at Government of India’s Open Government Data OGD platform


Features

  • DISCOVERY

Find the right API resource.

  • INFORMATION

Retrieve information about an API resource.

  • DATA

Download data in a convenient pandas DataFrame from the chosen API.

Prerequisites

  • An account on data.gov.in
  • An API key from the My Account page - (Instructions here : Official Guide)

Installation

  • Using PIP
pip install -U datagovindia

  • Clone the Git-Repository
git clone https://github.com/addypy/datagovindia

sudo python setup.py install

Basic Usage

Import Library

from datagovindia import DataGovIndia

Initialize Class

datagovin = DataGovIndia("579b464db66ec23bdd000001cdd3946e44ce4aad7209ff7b23ac571b")

Performs :

  1. Tests datagov.in API-server status.
  2. Validates API-Key. You only need to set this once.
  3. Fetches latest details about available APIs.

Search

datagovin.search(description="Wheat",max_results=3,print_results=True)

Output:

# Returns:
Showing 1 of 395 matching results      

==================================================================================

Resource-ID:	4c88fba5e3174e06a34af33194ab4b2d

Daily FCI Stock postion of the commodity Wheat, for the Haryana region in 2019 (till last week)

==================================================================================

Returns:

[{"4c88fba5e3174e06a34af33194ab4b2d": "Daily FCI Stock postion of the commodity Wheat, for the Haryana region in 2019 (till last week)"}]

Download Data

data = datagovin.get_data("b7ea044ea17149ed886c37ed5729b75a",num_results='all')
data.head()

Returns:

date code commodityid commodityname districtname districtcode stock commoditystock totalstock
2019-07-20T00:00:00Z Region Name: Haryana 01 Wheat(Including URS) FARIDABAD NC12 2214591.87343 35769407.44149 35769407.44149
2019-07-20T00:00:00Z Region Name: Haryana 01 Wheat(Including URS) HISSAR NC13 17954629.80074 35769407.44149 35769407.44149
2019-07-20T00:00:00Z Region Name: Haryana 01 Wheat(Including URS) KARNAL NC14 1787375.5789 35769407.44149 35769407.44149
2019-07-20T00:00:00Z Region Name: Haryana 01 Wheat(Including URS) KURUKSHETRA NC15 3552965.00293 35769407.44149 35769407.44149
2019-07-20T00:00:00Z Region Name: Haryana 01 Wheat(Including URS) ROHTAK NC16 10259845.18549 35769407.44149 35769407.44149


Detailed Examples


A. SETUP

Import DataGovIndia from datagovindia

from datagovindia import DataGovIndia

Get API-KEY from data.gov.in/user

See : Official Guide

api_key = "579b464db66ec23bdd000001cdd3946e44ce4aad7209ff7b23ac571b"

Initialize Class

# Initializing the library - 
# 1) Tests datagov.in API-server status.
# 2) Validates API-Key. You only need to set this once. 
# 2) Fetches latest details about available APIs. 


datagovin = DataGovIndia(api_key)

# The API key you provided is valid. You won't need to set it again.
# Latest resources loaded. You may begin.                                                    

B. DISCOVERY

Check available attributes

1. List of Organization-Names

datagovin.list_org_names()

# Returns: 
['Adi Dravidar and Tribal Welfare Department, Tamil Nadu',
 'Agriculture Department',
 'Agriculture Department, Meghalaya',
     ...,
 'Department of AIDS Control',
 'Department of Agricultural Research and Education (DARE)',
 'Department of Animal Husbandry, Dairying and Fisheries',
 'Department of Atomic Energy',
     ....,
 'Micro Small and Medium Enterprises Department, Tamil Nadu',
 'Ministry of Agriculture and Farmers Welfare',
    ....,
]

2. List of Organization-Types

datagovin.list_org_types()

# Returns: 
['Central',
 'City',
 'State']

3. List of Sectors

datagovin.list_sectors()

# Returns: 
['Adult Education',
'Agricultural',
'Agricultural Marketing',
'Agricultural Research & Extension',
'Agriculture',
    .
    .,
'Water Quality',
'Water Resources',
'Water and Sanitation',
'Water ways']

4. List of Sources

datagovin.list_sources()

# Returns:
['data.gov.in', 'smartcities.data.gov.in', 'tn.data.gov.in']

5. List of All Attributes

datagovin.list_all_attributes()
# Returns:
 { "org_types": ["Central", "City", "State"],  
  "sources": ["data.gov.in", "smartcities.data.gov.in", "tn.data.gov.in"],       
 "org_names": [ "Adi Dravidar and Tribal Welfare Department, Tamil Nadu",
                 "Agricultural Census, New Delhi",
                 "Agriculture Department",
                        ,
                        ,
                        ,
                 "Department of Agriculture, Cooperation and Farmers Welfare",
                 "Department of Animal Husbandry, Dairying and Fisheries",
                 "Department of Atomic Energy",
                 "Department of Ayurveda, Yoga and Naturopathy, Unani, Siddha "
                        ,
                        ,
                        ,
                 "Tourism, Culture and Religious Endowments Department",
                 "Transport Department, Madhya Pradesh",
                 "Transport Department, Tamil Nadu",
                        ,
                        ,
                 "West Bengal"],
  "sectors": [ "Adult Education",
               "Agricultural",
               "Agricultural Marketing",
               "Agriculture",
                        ,
                        ,          
               "Atmospheric Science",
               "Aviation",
               "Banking",
               "Biotechnology",
               "Broadcasting",
               "Census",
                        ,
                        ,          
               "District Adminstration",
               "Drinking Water",
               "Earth Sciences",,
               "Education",
               "Employment",
               "Environment and Forest",
                        ,
                        ,               
               "Municipal Waste",
               "National Population Register",
               "Natural Resources",
               "Noise Pollution",
               "Panchayati Raj",
               "Parliament Of india",
               "Passport",
               "Power and Energy",
                        ,
                        ,            
               "Water Quality",
               "Water Resources",
               "Water and Sanitation",
               "Water ways"]
               }

Searching for a dataset (API-Resource)

1. Search for resource using TITLE

results = datagovin.search_by_title("MGNREGA",max_results=5,print_results=True)
# Returns:
Showing 5 of 45 results for : `MGNREGA`

==================================================================================

Resource-ID:    bf1da9fc565045c3be3b0ba006377869

Expenditure under MGNREGA on Schedule Caste (SC) Persondays during 2015-16 and 2018-19 (From: Ministry of Rural Development)

==================================================================================

Resource-ID:    9aa66b7abb1d4e20bd4be5e68539cdfc

Central Fund Released to Jammu and Kashmir under MGNREGA from 2016-17 to 2018-19 (From: Ministry of Rural Development)

==================================================================================

Resource-ID:    57bff16a642345b29700ebcde6709937

State/UT-wise Expenditure Reported in Management Information System (MIS) under MGNREGA from 2014-15 to 2018-19 (From: Ministry of Labour and Employment)

==================================================================================

Resource-ID:    8e7b41bec79044958339c8da0a7f287e

State/UT-wise Expenditure made on Water Related Works Taken up under MGNREGA from 2016-17 to 2019-20 (From: Ministry of Jal Shakti)

==================================================================================

Resource-ID:    7371da1e4c5e4c529223f85e1756d24d

District-wise expenditure under the Mahatma Gandhi National Rural Employment Guarantee Act (MGNREGA) in the state Punjab from 2017-18 to 2019-20 (From: Ministry of Rural Development)

==================================================================================

2. Search for resource using DESCRIPTION

results = datagovin.search_by_description("Swachh Bharat Mission",max_results=5,print_results=True)
# Returns:
Showing 5 of 25 results for : `Swachh Bharat Mission`

==================================================================================

Resource-ID:    22f496bb32a84b6da4124f03c4b3ea62

District-wise Target vs Achievement of Construction of Toilets in State of Chhattisgarh under Swachh Bharat Mission (SBM) from 2013-14 to 2017-18 (From : Ministry of Tribal Affairs)

==================================================================================

Resource-ID:    673d72fc1c8a497d80477c3c72196e74

State/UT-wise Number of IHHLs Constructed under Swachh Bharat Mission - Gramin (SBM-G) from 02 October, 2014 to 17 July, 2019 (From : Ministry of Jal Shakti)

==================================================================================

Resource-ID:    2235bc9138cc4a4dbf5413e485596d5c

Funds Sanctioned, Allocated and Utilised under Swachh Bharat Mission (SBM) in Chhattisgarh from 2016-17 to 2018-19 (From: Ministry of Jal Shakti, Department of Drinking Water and Sanitation)

==================================================================================

Resource-ID:    45bb18686df44011b5fbbd5d74a01eda

Details of Fund (including Swachh Bharat Cess) Allocated & Released under Swachh Bharat Mission (Rural/Urban) from 2016-17 to 2018-19 (From: Ministry of Finance)

==================================================================================

Resource-ID:    5329bcc7f75f4a87be6a0bdaa6ebb4b4

Funds Allocated, Released, Balance and Utilization Certificate received under Swachh Bharat Mission (Urban) as on 30th November, 2019 (From: Ministry of Housing and Urban Affairs)

==================================================================================

3. Search for resources by SOURCE

results = datagovin.search_by_source("tn.data.gov.in",max_results=3,print_results=True)
# Returns:
Showing 3 of 526 results for `source` : `tn.data.gov.in`

==================================================================================

Resource-ID:    952da80341cd41e990bcbcb760ffbf90

Area, Production & Productivity of Snake Gourd (Vegetables) by District-wise in Tamil Nadu for the Year 2015-16

==================================================================================

Resource-ID:    0bd2498df63c456a9f336e242e9abe82

Area, Production & Productivity of Chrysanthimum (Flowers) by District-wise in Tamil Nadu for the Year 2015-16

==================================================================================

Resource-ID:    921f5b1f093146399c96a00195e17881

Area, Production & Productivity of Jadhi Malli (Flowers) by District-wise in Tamil Nadu for the Year 2015-16

==================================================================================

4. Search for resources by SECTOR

results = datagovin.search_by_sector("Banking",max_results=3,print_results=True)
# Returns:
Showing 3 of 45 results for `sector` : `Banking`

==================================================================================

Resource-ID:    4b9dd94d36be4f968578f8981857773c

Month-wise Progress Report of PMJDY by Public Sectors Banks/Regional Rural Banks/Private Banks upto 24-Feb-2016

==================================================================================

Resource-ID:    f719ee5c50254643aa54157d707d6077

Liabilities and assets of different classes of banks - scheduled commercial banks as on 31st March - State Bank of India from 2001 to 2014

==================================================================================

Resource-ID:    371020a7a43747df8946fbd030b53459

Liabilities And Assets Of State Financial Corporations (State-wise) upto 2012-13

==================================================================================

5. Search for resources by ORG-NAME

results = datagovin.search_by_org_name("Ministry of Road Transport and Highways",max_results=5,print_results=True)
# Returns:
Showing 5 of 417 results for `organization` - `Ministry of Road Transport and Highways`

==================================================================================

Resource-ID:    37b1f841f44c490682fb2442b0f2bd25

State/UT-wise Length of Roads under Coal Fields/Coal units of Coal India Limited by Type of Surface as on 31st March, 2017

==================================================================================

Resource-ID:    b10ac9f5c1fd42c78c19e74a1fe64c04

State/UT-wise Length of Roads under Forest Departments by Type of Surface in India as on 31st March, 2017

==================================================================================

Resource-ID:    8ebce90f62e8421592672bf22bac7f94

State-wise Length of Roads in Major Ports by Type of Surface as on 31st March, 2017

==================================================================================

Resource-ID:    888f4d498c864f1c825feef9db674cc8

State/UT-wise Length of Military Engineering Service Roads by Type of Surface as on 31st March, 2017

==================================================================================

Resource-ID:    068ecf9440694838981b3529c3a48edc

State/UT-wise Length of PMGSY Roads by type of Surface as on 31st March, 2017

==================================================================================

6. Search for resources by ORG-TYPE

results = datagovin.search_by_org_type("State",max_results=5,print_results=True)
# Returns:
Showing 5 of 645 results for `organization type` - `State`

==================================================================================

Resource-ID:    4200eb5f17294fee8477af5feb715b3c

Details of Vehicle Tax collected by Surat Municipal Corporation from Year 1989 onward

==================================================================================

Resource-ID:    fbdf3432b88a4592bbc4d0f60a0ac140

Surat City Bus and BRTS Passenger Information from April 2015 (daily)

==================================================================================

Resource-ID:    993acfe3b72e4e07895915aa34bc226d

Building Plan Applications at Surat Municipal Corporation from April 2015 onward (daily)

==================================================================================

Resource-ID:    8addc59332b54531a2346057209f35a0

Surat City Complaint Statistics from April 2015 onward (daily)

==================================================================================

Resource-ID:    3968cb03596842c9ac43cba988a964c7

Garbage Collection in Surat City (in KG) from April 2015 onward (daily) 

==================================================================================

7. Search for resources with Multiple Filters

results = datagovin.search(title="COVID",
                            description="Postiive Case",
                            org_name="Surat",
                            org_type="City",
                            sector="All",
                            source="smartcities.data.gov.in",
                            max_results=5,
                            print_results=True,
                          )
# Returns:
Showing 2 of 2 matching results        

==================================================================================

Resource-ID:    b9cfed4ca1a24f7aaffa88a8e1a2149c

COVID-19 Positive Case Details

==================================================================================

Resource-ID:    ee35f0724d804b418c17fd74414907be

COVID-19 Cluster / Containment Zone Details

==================================================================================

C. Learn more about an API-resource.

1. Get all available meta-data for an API resource

Meta-Data includes -

  • Resource-ID
  • Title
  • Description
  • Total records available
  • Date-Created
  • Data-Updated
  • Organization-Type
  • Organization-Name
  • Source
  • Sector
  • Fields
datagovin.get_resource_info("b9cfed4ca1a24f7aaffa88a8e1a2149c")
{"ResourceID": "b9cfed4ca1a24f7aaffa88a8e1a2149c",
 "Title": "COVID-19 Positive Case Details",
 "Description": "COVID-19 Positive Case Details",
 "TotalRecords": 3592,
 "DateCreated": "08 May 2020, 09:00 PM",
 "DateUdpated": "10 January 2021, 11:04 PM",
 "OrganizationNames": ["Gujarat", "Surat"],
 "OrganizationTypes": "City",
 "Sector": "All",
 "Source": "smartcities.data.gov.in",
 "Fields": ["sr_no",
            "city",
            "zone",
            "age",
            "gender",
            "latitude",
            "longitude",
            "result",
            "sample_result",
            "resultdate"]}

2. Get details of fields (variables) available for a resource.

datagovin.get_resource_fields("b9cfed4ca1a24f7aaffa88a8e1a2149c")
field_code field_label field_type
0 sr_no Sr.No keyword
1 city City keyword
2 zone zone double
3 age age double
4 gender Gender keyword
5 latitude latitude double
6 longitude longitude double
7 result Result keyword
8 sample_result Sample_Result keyword
9 resultdate ResultDate date

D. Download DATA

data = datagovin.get_data("b9cfed4ca1a24f7aaffa88a8e1a2149c")
data.head(20)
sr_no city zone age gender latitude longitude result sample_result resultdate
0 1 Surat South West Zone 21 F 21.1697 72.7933 Cured/Discharged Positive 19/03/2020
1 2 Surat Central Zone 67 M 21.1869 72.816 Death Positive 20/03/2020
2 3 Surat East Zone - B 50 F 21.21130173 72.86820564 Cured/Discharged Positive 10/06/2020
3 4 Surat South Zone 26 M 21.1397 72.8241 Cured/Discharged Positive 28/03/2020
4 5 Surat West Zone 55 M 21.2056124 72.804538 Cured/Discharged Positive 11/06/2020
5 6 Surat North Zone 47 M 21.2419426 72.8287933 Cured/Discharged Positive 13/06/2020
6 7 Surat East Zone - B 34 M 21.2225309 72.8918084 Cured/Discharged Positive 17/06/2020
7 8 Surat North Zone 39 M 21.2334082 72.8046628 Cured/Discharged Positive 19/06/2020
8 9 Surat South East Zone 20 F 21.1681 72.8672 Cured/Discharged Positive 18/04/2020
9 10 Surat West Zone 32 M 21.2265 72.7927 Cured/Discharged Positive 21/03/2020
10 11 Surat Central Zone 45 M 21.1852 72.8209 Cured/Discharged Positive 22/03/2020
11 12 Surat South Zone 22 M 21.1613 72.8305 Cured/Discharged Positive 01/04/2020
12 13 Surat South East Zone 62 M 21.186 72.863 Cured/Discharged Positive 23/03/2020
13 14 Surat West Zone 67 M 21.2212 72.7954 Cured/Discharged Positive 29/03/2020
14 15 Surat South West Zone 23 M 21.1738 72.8141 Cured/Discharged Positive 20/03/2020
15 16 Surat North Zone 29 M 21.2264 72.8189 Cured/Discharged Positive 31/03/2020
16 17 Surat West Zone 61 F 21.2078 72.7732 Death Positive 03/04/2020
17 18 Surat South Zone 40 F 21.1612 72.8303 Cured/Discharged Positive 04/04/2020
18 19 Surat Central Zone 65 M 21.1956 72.8353 Death Positive 04/04/2020
19 20 Surat West Zone 50 M 21.2015 72.8085 Cured/Discharged Positive 05/04/2020

E. Filtering

# First, let's take a look at valid `fields`.

datagovin.get_resource_fields("b9cfed4ca1a24f7aaffa88a8e1a2149c")
field_code field_label field_type
0 sr_no Sr.No keyword
1 city City keyword
2 zone zone double
3 age age double
4 gender Gender keyword
5 latitude latitude double
6 longitude longitude double
7 result Result keyword
8 sample_result Sample_Result keyword
9 resultdate ResultDate date

1. Filtering with a Single Field - Single Value pair

data = datagovin.get_data("b9cfed4ca1a24f7aaffa88a8e1a2149c",filters={"result":"Active"})
data
sr_no city zone age gender latitude longitude result sample_result resultdate
0 511 Surat South East Zone 25 M 21.179004 72.808405 Active Positive 25/04/2020
1 951 Surat South East Zone 35 M 21.1904773 72.849517 Active Positive 13/05/2020
2 1111 Out City NA 70 F 21.150554 72.802457 Active Positive 18/05/2020
3 1164 Out City NA 73 M 21.150554 72.802457 Active Positive 19/05/2020
4 1166 Surat South Zone 41 M 21.153726 72.839782 Active Positive 20/05/2020
5 1247 Surat South Zone 55 M 21.153215 72.8267782 Active Positive 24/05/2020
6 1361 Surat South West Zone 50 F 21.13268974 72.74215644 Active Positive 24/05/2020
7 1520 Out City NA 72 M 21.2217492 72.7830429 Active Positive 28/05/2020
8 1530 Out City NA 56 F 21.1577 72.7768399 Active Positive 28/05/2020
9 1594 Out City NA 53 F 21.1563151 72.766301 Active Positive 30/05/2020
10 2327 Surat South Zone 63 M 21.1223137 72.8491477 Active Positive 10/06/2020
11 2485 Out City NA 41 M 21.29079 72.9001 Active Positive 13/06/2020
12 2609 Surat North Zone 61 M 21.2366751 72.8350334 Active Positive 14/06/2020
13 2748 Out City NA 3 F 21.13488745 72.76593804 Active Positive 16/06/2020

2. Filtering with a Single Field - Multiple Values

datagovin.get_data("b9cfed4ca1a24f7aaffa88a8e1a2149c",filters={"result":["Active",'Cured/Discharged']})
sr_no city zone age gender latitude longitude result sample_result resultdate
0 511 Surat South East Zone 25 M 21.179004 72.808405 Active Positive 25/04/2020
1 951 Surat South East Zone 35 M 21.1904773 72.849517 Active Positive 13/05/2020
2 1111 Out City NA 70 F 21.150554 72.802457 Active Positive 18/05/2020
3 1164 Out City NA 73 M 21.150554 72.802457 Active Positive 19/05/2020
4 1166 Surat South Zone 41 M 21.153726 72.839782 Active Positive 20/05/2020
... ... ... ... ... ... ... ... ... ... ...
3009 3189 Surat North Zone 50 M 21.226217 72.817604 Cured/Discharged Positive 21/06/2020
3010 3190 Surat North Zone 42 M 21.2268099 72.8256378 Cured/Discharged Positive 21/06/2020
3011 3191 Surat West Zone 52 M 21.205124 72.776736 Cured/Discharged Positive 22/06/2020
3012 3193 Surat North Zone 26 F 21.2398084 72.8500394 Cured/Discharged Positive 21/06/2020
3013 3194 Surat North Zone 49 M 21.2290168 72.808571 Cured/Discharged Positive 21/06/2020

3014 rows × 10 columns

3. Filtering with Multiple Field(s) - Multiple Value(s)

datagovin.get_data("b9cfed4ca1a24f7aaffa88a8e1a2149c",
                   filters={
                       "gender":["F","M"],
                       "result":['Cured/Discharged',"Death"],
                   })

# Note:
# Filtering returns a UNION of matching results, and NOT an INTERSECTION.
sr_no city zone age gender latitude longitude result sample_result resultdate
0 1 Surat South West Zone 21 F 21.1697 72.7933 Cured/Discharged Positive 19/03/2020
1 3 Surat East Zone - B 50 F 21.21130173 72.86820564 Cured/Discharged Positive 10/06/2020
2 9 Surat South East Zone 20 F 21.1681 72.8672 Cured/Discharged Positive 18/04/2020
3 17 Surat West Zone 61 F 21.2078 72.7732 Death Positive 03/04/2020
4 18 Surat South Zone 40 F 21.1612 72.8303 Cured/Discharged Positive 04/04/2020
... ... ... ... ... ... ... ... ... ... ...
5807 3506 Surat West Zone 47 M 21.2057962 72.7998015 Cured/Discharged Positive 23/06/2020
5808 3508 Surat South Zone 78 M 21.159747 72.838655 Cured/Discharged Positive 23/06/2020
5809 3509 Surat East Zone - A 30 M 21.1975074 72.8450123 Cured/Discharged Positive 24/06/2020
5810 3510 Surat North Zone 43 M 21.2284002 72.8283048 Cured/Discharged Positive 23/06/2020
5811 3511 Surat North Zone 53 M 21.2440121 72.8502404 Cured/Discharged Positive 23/06/2020

3592 rows × 10 columns


F. Restricting Variables/ Columns - fields

datagovin.get_data("b9cfed4ca1a24f7aaffa88a8e1a2149c",
                    fields = ["city","zone","age","gender","result"],
                   )
# Get only the fields you need, by passing a list of valid fields in `fields` 
city zone age gender result
0 Surat South West Zone 21 F Cured/Discharged
1 Surat Central Zone 67 M Death
2 Surat East Zone - B 50 F Cured/Discharged
3 Surat South Zone 26 M Cured/Discharged
4 Surat West Zone 55 M Cured/Discharged
5 Surat North Zone 47 M Cured/Discharged
6 Surat East Zone - B 34 M Cured/Discharged
7 Surat North Zone 39 M Cured/Discharged
8 Surat South East Zone 20 F Cured/Discharged
9 Surat West Zone 32 M Cured/Discharged
10 Surat Central Zone 53 M Cured/Discharged
11 Surat South East Zone 45 F Cured/Discharged
12 Surat South East Zone 60 F Cured/Discharged
13 Surat North Zone 65 M Death
14 Surat South East Zone 18 M Cured/Discharged
15 Surat South Zone 40 M Cured/Discharged
16 Surat East Zone - A 28 F Cured/Discharged
17 Surat North Zone 77 F Cured/Discharged
18 Surat East Zone - A 62 M Cured/Discharged
19 Surat East Zone - A 24 F Cured/Discharged
20 Surat North Zone 63 M Cured/Discharged
22 Surat South East Zone 33 M Cured/Discharged
23 Surat North Zone 34 M Cured/Discharged
24 Surat Central Zone 24 M Cured/Discharged
25 Surat South East Zone 34 M Cured/Discharged
26 Surat North Zone 34 F Cured/Discharged
27 Surat South Zone 43 M Cured/Discharged
28 Surat North Zone 52 F Cured/Discharged
30 Surat North Zone 33 M Cured/Discharged
31 Surat West Zone 46 M Cured/Discharged
32 Surat East Zone - B 38 M Cured/Discharged
33 Surat South West Zone 70 M Cured/Discharged
34 Surat West Zone 44 M Cured/Discharged
35 Surat South West Zone 45 M Cured/Discharged
36 Surat North Zone 36 M Cured/Discharged
37 Surat Central Zone 40 M Cured/Discharged
39 Surat East Zone - A 37 M Cured/Discharged

G. Request data sorted by a valid field

datagovin.get_data("b9cfed4ca1a24f7aaffa88a8e1a2149c",
                fields = ["city","zone","age","gender","result"],
                   sort_key = 'age',
                   sort_order = 'asc'
                   )

# Sort `field` in Ascending order using `asc`=`Ascending`
city zone age gender result
0 Surat South East Zone 1 M Cured/Discharged
1 Surat East Zone - A 1 F Cured/Discharged
2 Surat South Zone 1 M Cured/Discharged
3 Surat North Zone 1 M Cured/Discharged
4 Surat North Zone 2 F Cured/Discharged
5 Surat Central Zone 2 F Cured/Discharged
6 Surat South East Zone 2 M Cured/Discharged
7 Surat East Zone - A 2 M Cured/Discharged
8 Surat North Zone 2 M Cured/Discharged
9 Surat North Zone 3 M Cured/Discharged
10 Surat North Zone 34 F Cured/Discharged
11 Surat North Zone 34 M Cured/Discharged
12 Surat South East Zone 34 M Cured/Discharged
17 Surat East Zone - A 34 M Death
20 Surat South East Zone 47 F Cured/Discharged
21 Surat West Zone 47 M Cured/Discharged
22 Surat East Zone - B 47 M Cured/Discharged
23 Surat East Zone - A 47 M Cured/Discharged
25 Surat North Zone 47 M Cured/Discharged
26 Surat South West Zone 47 M Death
30 Surat South East Zone 60 M Cured/Discharged
31 Surat South East Zone 60 F Cured/Discharged
33 Surat South East Zone 60 M Death
35 Surat South East Zone 60 F Death
36 Surat North Zone 60 F Cured/Discharged
37 Surat South Zone 60 F Cured/Discharged
datagovin.get_data("b9cfed4ca1a24f7aaffa88a8e1a2149c",
                   fields = ["city","zone","age","gender","result"],                   
                   sort_key = 'age',
                   sort_order = 'desc'
                   )
# Sort `field` in Descending order using `desc`=`Descending`
city zone age gender result
0 Surat North Zone 94 M Cured/Discharged
1 Surat North Zone 90 F Death
2 Surat East Zone - B 89 M Cured/Discharged
3 Surat North Zone 88 M Cured/Discharged
4 Surat North Zone 88 F Death
5 Surat North Zone 86 M Cured/Discharged
6 Surat South East Zone 86 M Death
7 Surat North Zone 85 M Cured/Discharged
8 Surat North Zone 85 F Cured/Discharged
10 Surat South East Zone 54 M Cured/Discharged
11 Surat North Zone 54 F Cured/Discharged
12 Surat South West Zone 54 M Cured/Discharged
16 Surat South Zone 54 M Cured/Discharged
17 Surat Central Zone 54 F Cured/Discharged
18 Surat South Zone 54 F Cured/Discharged
19 Surat Central Zone 54 M Cured/Discharged
20 Surat Central Zone 42 M Cured/Discharged
21 Surat Central Zone 42 F Cured/Discharged
22 Surat East Zone - A 42 M Cured/Discharged
23 Surat South West Zone 42 F Cured/Discharged
24 Surat South Zone 42 M Cured/Discharged
27 Surat East Zone - B 42 M Cured/Discharged
28 Surat South East Zone 42 M Cured/Discharged
30 Surat Central Zone 27 F Cured/Discharged
31 Surat West Zone 27 M Cured/Discharged
32 Surat South East Zone 27 M Cured/Discharged
33 Surat South West Zone 27 F Cured/Discharged
35 Surat Central Zone 27 M Cured/Discharged
39 Surat South Zone 27 M Cured/Discharged

H. ADVANCED : Multi-Threading API-requests

- Multi-Threading is disabled by default.

- You can enable multi-threading for faster performance on large datasets.

datagovin.get_resource_info("dad7a738fd3b437dad31e1f844e9a575")['TotalRecords']
# Returns:
20197

To Enable Multi-threading -

datagovin.enable_multithreading()
# Returns:
Multi-Threaded API requests enabled.
%%timeit
datagovin.get_data("dad7a738fd3b437dad31e1f844e9a575",num_results='all')
# Returns:
258 ms ± 11.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

To Disable Multi-threading -

datagovin.disable_multithreading()
# Returns:
Multi-Threaded API requests disabled.
%%timeit
datagovin.get_data("dad7a738fd3b437dad31e1f844e9a575",num_results='all')
# Returns:
2.74 s ± 194 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

Documentation

Authors :

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datagovindia-0.2.tar.gz (37.6 kB view hashes)

Uploaded Source

Built Distribution

datagovindia-0.2-py3-none-any.whl (31.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page