Skip to main content

Data from National Bureau of Statistics, China

Project description

Retrieving Data from China National Bureau of Statistics

https://data.stats.gov.cn/easyquery.htm

Installation

pip install nbsdata

Usage

from nbsdata import NBS
bs = NBS()

Get Databases

bs.databases

Get Region Codes

province-level or city-level

bs.regioncode('浙江')   # 330000
bs.regioncode('杭州', city = True)   # 330100

Query Indicator Codes

Indicator codes for each database are retrived with module get_nbs_indicators (in directory 'rhopy')

Indicator data files are stored in package's 'asset' directory. The indicators are somewhat stable. We will update them if needed.

To update these files, run related function in module 'get_nbs_indicators'

NB: With method 'indicatorcode()', we can only get those indicators which appear in the selection bar on the left in the official pages. Those leaf-level indicators which only appear in the table need to be queried with 'leafindicator()' further

bs.indicatorcode('fsjd', '可支配收入')
bs.leafindicator('fsjd', 'A0301')

National Data

Case: Annual data of GDP in the last 5 years ('LAST5', mrv = 5)

Step 1: query indicator code

bs.indicatorcode('hgnd', '生产总值')

Now we can get the code: 'A0201'

Step 2: get data

gdp = bs.nationaldata('hgnd', 'A0201', 'LAST5')

We can see indicator code 'A0201' contains the following sub-codes: 'A010101' (国民总收入), 'A020102' (国内生产总值), ..., 'A020106' (人均国内生产总值)

Step 3:

Filter from the dataframe above

import polars as pl
gdp.filter(pl.col('indicator_code') == 'A020102')

Or retrieve data again with subcode 'A020102'


bs.nationaldata('hgnd', 'A020102', 'LAST5')

Regional Data

For single region (e.g. Zhejiang), we can retrieve data with either category-level or leaf-level indicator; for all regions, we can only use leaf-level indicator, or you will only get the data of the first subcode of the category-level indicator.

Case 1: Quarterly data of urban disposable income of Zhejiang from '2010Q1' to '2025Q3'

Step 1: query indicator code

bs.indicatorcode('fsjd', '城镇居民.+可支配收入')

We get nothing, because the indicator code is not available. Loose the query condition

bs.indicatorcode('fsjd', '可支配收入')

Now we get one item named '居民人均可支配收入', the code is 'A0301'

Step 2: get data with code 'A0301'

bs.regionaldata('fsjd', 'A0301', '2010A-2025C', '330000')

The result above contains the following subcodes: 'A030101' (居民人均可支配收入), 'A030102' (城镇居民人均可支配收入), 'A030103' (农村居民人均可支配收入)

Step 3: Filter data or retrieve data again with subcode 'A030102'

Case 2: Quarterly data of urban disposable income of of All provinces from '2020Q1' to '2025Q3'

Use category-level indicator, say, 'A0301'

bs.leafindicator('fsjd', 'A0301')
bs.regionaldata('fsjd', 'A030102', '2020A-2025C')

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nbsdata-1.0.0-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

Details for the file nbsdata-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nbsdata-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 47.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for nbsdata-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9aa51fb523c3102508779402c63b13ce5c20ba332b486326b624e7e8e17bf8d
MD5 d1f68649c58d20dc1afce5eaa44bedc9
BLAKE2b-256 502e5f2490c74e9721d0940f293621f7cc99b2a50a7d8149ac364ece613b7eca

See more details on using hashes here.

Supported by

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