A Python package to explore IPUMS data.
Project description
PyIPUMS
PyIPUMS is a library for working with data from IPUMS.
Example
Example that provides the IPUMS metadata in a dictionary.
import json
import pandas as pd
from src.pyipums.parse_xml import read_ipums_ddi
from ipumspy import readers, ddi
def read_ipums_micro(ddi, data_file_path, n_max=None):
# Read the fixed-width data file using the extracted column information
df = pd.read_fwf(
data_file_path,
dtypes=ddi["column_dtypes"],
colspecs=ddi["column_specs"],
header=None,
names=ddi["columns"],
nrows=n_max,
compression="gzip",
)
return df
def main():
ddi_file_path = "./usa_00003.xml"
data_file_path = "./usa_00003.dat.gz"
cps_ddi = read_ipums_ddi(ddi_file_path)
print(json.dumps(cps_ddi["file_metadata"], indent=2))
cps_data = read_ipums_micro(cps_ddi, data_file_path, n_max=100)
print(cps_data.head())
Modifying
If you are looking to make changes to the library I recommend using poetry.
poetry env use 3.8
pyenv shell 3.8
poetry shell
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyipums-0.0.4.tar.gz
(6.1 kB
view details)
Built Distribution
File details
Details for the file pyipums-0.0.4.tar.gz
.
File metadata
- Download URL: pyipums-0.0.4.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a70ee417feb09f74e9fabaee43bc3dfbfe7b0e95f5afcc950a5510af90c74cf5 |
|
MD5 | b07d1f28e3310ee8b1473ba5731f6b8d |
|
BLAKE2b-256 | 07b693881a815126aa348d109c4c5d445df00294cf5cd0e389bc60417e191a64 |
File details
Details for the file pyipums-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: pyipums-0.0.4-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 068973eb4303a82ead02e4e4b5757f9a798982c9789264fce617d1f2b60f480c |
|
MD5 | a90a2c8e34879365992854eeaf063a82 |
|
BLAKE2b-256 | 9d7d162595ee18be88c7c2a3b024bb8753c1cae5b40c0456f5cfddd9296d1968 |