PC-Axis PX file reader
Project description
PC-Axis reader for Python
pxrd is a package for reading data from PX (PC-Axis) statistics files. The specifications for the format can be found here.
The pxrd module allows for parsing of keywords and data from PX files at low level. The parser supports KEY based data as well as NO KEY data. Support for multilanguage is implemented.
Instalation
pip install pxrd
Pandas integration
There's an additional module in the package that allows for conversion to Pandas DataFrame. It's separated to avoid direct dependency to pandas if it's not required.
To read files into a Pandas DataFrame:
import pxrd
from pxrd.pandas import to_pandas
px = pxrd.read('/path/to/pxfile.px')
df = to_pandas(px, categories=True, multiindex=True)
When converting to Pandas there are two options:
- categories (default: True): if True, the resulting DataFrame uses Categorical dtype for the stub and heading columns/indexes. Else, it uses zero based indexes into the dimension values/codes.
- multiindex (default: False): if True, the generated DataFrame uses Pandas MultiIndex. Else is a regular DataFrame with stub and headings as columns.
Command Line Interface
The packages installs a command line shortcut for converting PC-Axis files to CSV. It supports multilanguage PC-Axis files.
$ px2csv [-h] [--languages] [--language LANGUAGE] filename
Use the --languages options to obtain a list of available languages and --language LAMGUAGE to specify the selected language. If no language is specified, the default language is used.
Low level usage
First, you use read() to parse the PX-File. If you obtain the file via requests or any other mean, you can use reads() and provide the string contents of the file. Both functions return a PxFile object you can use to query the contents of the file.
PxFile.keywords()
Returns a list of the keywords found in the file, excluding "DATA"
PxFile.language()
Returns the default language of the file, None if it's not defined
PxFile.languages()
Returns the list of languages available in the file
PxFile.keyword(keyword, subkey=None, language=None)
Returns the value of the specified keyword in the specfied language or default if None. If a keyword has a subkey you cam query it using the subkey parameter
PxFile.variables(language=None)
Returns the dimensions of the cube (stub + headings) in the specified language or default if None
PxFile.values(variable, language=None)
Returns the values for the dimension (or variable) usign the language indicated or the default if None
PxFile.codes(variable, language=None)
Returns the codes for the dimension (or variable) usign the language indicated or the default if None. If there are no codes, it returns the same values as "values()"
PxFile.datum(index)
Returns the value for the specified index of the cube. The index must be in the forma of a list containing the integer indexes of the values/codes of the variable. The order of the dimensions/variables in the index is the same as returned by "variables()".
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
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 pxrd-0.0.3.tar.gz.
File metadata
- Download URL: pxrd-0.0.3.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.0.1 pkginfo/1.7.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62b67336791c1bf5c340011636e52ea5cbe46737bb45d1ad7d244c5f463fc74f
|
|
| MD5 |
059f9314ee4962636b45e72d553fff01
|
|
| BLAKE2b-256 |
5b7489c4a62e8408d54d3e132c60d2836dc685c3b165864de8118550ab7914eb
|
File details
Details for the file pxrd-0.0.3-py3-none-any.whl.
File metadata
- Download URL: pxrd-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.0.1 pkginfo/1.7.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c704c334d90162d1f9332cf61187d2ec867ef9af7b60b0d50bc8c8ce3ab5a77
|
|
| MD5 |
6880b32c76fc3c723224494f86ded9ce
|
|
| BLAKE2b-256 |
4939685fa296058dc9fe4606ec0a8e10751064d2bc2af56db9f1d8465dd9999a
|