Unofficial package for PNADC microdata (IBGE)
Project description
py-pnadc: Unofficial Python Package for PNADcIBGE
:us: English
About this package
py-pnadc is a Python package containing tools for downloading and reading the microdata from the Continuous National Household Sample Survey (PNAD Contínua) from Brazilian Institute of Geography and Statistics (IBGE).
This package solves common issues related to handling large PNADC files by streaming data in stream and converting it directly to .parquet.
It provides a pythonic alternative to the R official package.
Main funcionalities
- Analytics-ready: Converts the Fixed-Width-Files (FWF) files direct to .parquet.
- Low RAM consumption: Processes data in chunks, enabling execution in regular notebooks.
- Automatic ETL: Manages downloading, layout parsing and convertion in a single command.
Installation / Instalação
Development mode (local)
To install the package locally to download and read the microdata:
git clone https://github.com/andre-kmp/py-pnadc.git
cd py-pnadc
pip install .
How to use it
Running the main function
import pnadc
# This will:
# 1. Download the layout and the microdata (if they don't exist yet)
# 2. Convert to .parquet
# 3. Return a pandas dataframe with the selected columns
df = pnadc.load_microdata()
print(df.head())
Setting parameters
You may override the package defaults by passing arguments directly to the load_microdata function.
- columns_to_keep: List of columns (IBGE codes) to keep.
- load_years: List of years to process (e.g.:
['2023', '2024']). - chunk_size: Number of rows per batch in memory (reduce it for low RAM environments). Default is 25,000.
Usage example:
import pnadc
# 1. Setting preferences
my_columns = ['UF', 'V2007', 'V2009', 'VD4001', 'VD4002']
target_years = ['2023', '2024']
# 2. Loading data with custom arguments
df = pnadc.load_microdata(
columns_to_keep=my_columns,
load_years=target_years,
chunk_size=10000
)
print(f"Loaded data: {df.shape}")
print(df.head())
:warning: Disclaimer
This is an unofficial project and is not affiliated with IBGE.
:brazil: Português
Sobre este pacote
py-pnadc é um pacote Python com ferramentas para baixar e ler os microdados da Pesquisa Nacional de Domicílios Contínua (PNADC) do Instituto Brasileiro de Geografia e Estatística (IBGE).
Esse pacote resolve os problemas comuns ao lidar com os arquivos de texto gigantes da PNADC, processando os dados em stream e convertendo-os para .parquet.
É uma alternativa pythonica ao pacote oficial em R.
Principais funcionalidades
- Eficiente para análises: Converte os arquivos de largura fixa (FWF) diretamente para .parquet.
- Baixo consumo de RAM: Processa os dados em chunks, o que permite rodar em notebooks comuns.
- ETL automático: Gerencia o download, leitura do layout e conversão em um único comando.
Instalação
Modo de desenvolvedor (local)
Para instalar o pacote localmente para baixar e ler os microdados:
git clone https://github.com/andre-kmp/py-pnadc.git
cd py-pnadc
pip install .
Como usar
Rodando a função principal
import pnadc
# Isso irá:
# 1. Baixar o dicionário e os dados (se ainda não existirem)
# 2. Converter para Parquet
# 3. Retornar um pandas DataFrame com as colunas selecionadas
df = pnadc.load_microdata()
print(df.head())
Configurando os parâmetros
Você pode sobrescrever os padrões do pacote passando argumentos diretamente para a função load_microdata:
- columns_to_keep: Lista de colunas (códigos do IBGE) para manter.
- load_years: Lista de anos a serem processados (ex:
['2023', '2024']). - chunk_size: Número de linhas por lote na memória (diminua se tiver pouca RAM). Por default, 25000.
Exemplo de uso:
import pnadc
# 1. Definindo suas preferências
minhas_colunas = ['UF', 'V2007', 'V2009', 'VD4001', 'VD4002']
anos_alvo = ['2023', '2024']
# 2. Carregando os dados com os seus argumentos
df = pnadc.load_microdata(
columns_to_keep=minhas_colunas,
load_years=anos_alvo,
chunk_size=10000
)
print(f"Dados carregados: {df.shape}")
print(df.head())
:warning: Isenção de responsabilidade
Este é um projeto não-oficial e não possui afiliação com o IBGE.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_pnadc-0.1.4.tar.gz.
File metadata
- Download URL: py_pnadc-0.1.4.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bda60a1b153c7d39ebe350a74ca6d00317a468af0581f26643077e277a6bcef
|
|
| MD5 |
dca8d5001081d36ea28d34b81aba8a39
|
|
| BLAKE2b-256 |
8d3f21c4c7f350ad808f5e2126b637d19a2d3f794349e040c38b8df322370d41
|
Provenance
The following attestation bundles were made for py_pnadc-0.1.4.tar.gz:
Publisher:
python-publish.yml on andre-kmp/py-pnadc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_pnadc-0.1.4.tar.gz -
Subject digest:
2bda60a1b153c7d39ebe350a74ca6d00317a468af0581f26643077e277a6bcef - Sigstore transparency entry: 764656899
- Sigstore integration time:
-
Permalink:
andre-kmp/py-pnadc@9a0bb4a4b9d6129b506e18a933f24e94ec21cfb6 -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/andre-kmp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9a0bb4a4b9d6129b506e18a933f24e94ec21cfb6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file py_pnadc-0.1.4-py3-none-any.whl.
File metadata
- Download URL: py_pnadc-0.1.4-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87a4d732072f90feac7d4ffbc10ccccad27712d6751f37fd21ec3e55db61fceb
|
|
| MD5 |
c65c105c9f5b7dbe8de6b01a26e46c89
|
|
| BLAKE2b-256 |
37cecd4acccb7f4b80bebec53f2205c228933e671f850fa071d4b39a5752e982
|
Provenance
The following attestation bundles were made for py_pnadc-0.1.4-py3-none-any.whl:
Publisher:
python-publish.yml on andre-kmp/py-pnadc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_pnadc-0.1.4-py3-none-any.whl -
Subject digest:
87a4d732072f90feac7d4ffbc10ccccad27712d6751f37fd21ec3e55db61fceb - Sigstore transparency entry: 764656905
- Sigstore integration time:
-
Permalink:
andre-kmp/py-pnadc@9a0bb4a4b9d6129b506e18a933f24e94ec21cfb6 -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/andre-kmp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9a0bb4a4b9d6129b506e18a933f24e94ec21cfb6 -
Trigger Event:
release
-
Statement type: