Skip to content

kustij/px2csv

Repository files navigation

px2csv

Convert PX (PC-Axis) files to CSV fast and memory-efficiently in Python.

We currently support only UTF-8 encoded PX files.

Install from PyPI

pip install px2csv

Convert using file paths

from px2csv import convert
convert("examples/12b4.px", "examples/12b4.csv", include_codes=True, include_labels=True)

For large sparse PX files, skip missing values and avoid repeated label columns:

from px2csv import convert
convert(
	"examples/132g.px",
	"examples/132g.csv",
	include_codes=True,
	include_labels=False,
	skip_empty=True,
)

Convert using file-like objects (streams)

import io
from px2csv import convert
with open("examples/12b4.px", "rb") as fin, open("examples/12b4.csv", "wb") as fout:
	convert(fin, fout, include_codes=True, include_labels=True)

Filter rows while converting (select)

Pass select to keep only the rows you need. Filtering happens inside the C++ converter, so the discarded rows are never materialized.

from px2csv import convert
convert(
	"examples/12b4.px",
	"examples/12b4.csv",
	include_codes=True,
	include_labels=True,
	select={
		"Tiedot": ["arvogwh", "osuuskk"],
		"Vuosi": ["2024", "2023"],
	},
)

select maps a dimension name to the list of value codes to keep; Only rows that match every selected dimension are emitted; dimensions omitted from select are kept in full.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors