Crosstabulates data in a text file.
Project description
xtab.py is a Python module and command-line program that rearranges data from a normalized format to a crosstabulated format. It takes data in this form:
Station |
Date |
Value |
WQ-01 |
2006-05-23 |
4.5 |
WQ-02 |
2006-05-23 |
3.7 |
WQ-03 |
2006-05-23 |
6.8 |
WQ-01 |
2006-06-15 |
9.7 |
WQ-02 |
2006-05-15 |
5.1 |
WQ-03 |
2006-06-15 |
7.2 |
WQ-01 |
2006-07-19 |
10 |
WQ-02 |
2006-07-19 |
6.1 |
WQ-03 |
2006-07-19 |
8.8 |
and rearranges it into this form:
Station |
2006-05-23 |
2006-06-15 |
2006-07-19 |
WQ-01 |
4.5 |
3.7 |
6.8 |
WQ-02 |
9.7 |
5.1 |
7.2 |
WQ-03 |
10 |
6.1 |
8.8 |
Input and output are both text (CSV) files.
A summary of its capability and usage is shown below. Full documentation is available at http://xtab.osdn.io/.
Capabilities
You can use the xtab program to:
Rearrange data exported from a database to better suit its subsequent usage in statistical, modeling, graphics, or other software, or for easier visual review and table preparation.
Convert a single file (table) of data to a SQLite database.
Check for multiple rows of data in a text file with the same key values.
Notes
Multiple data values can be crosstabbed, in which case the output will contain multiple sets of similar columns.
Either one or two rows of headers can be produced in the output file. One row is the default, and is most suitable when the output file will be further processed by other software. Two rows facilitate readability when the output contains multiple sets of similar columns.
The xtab program does not carry out any summarization or calculation on the data values, and therefore there should be no more than one data value to be placed in each cell of the output table. More than one value per cell is regarded as an error, and in such cases only one of the multiple values will be put in the cell.
Error messages can be logged to either the console or a file. If no error logging option is specified, then if there are multiple values to be put in a cell (the most likely data error), a single message will be printed on the console indicating that at least one error of this type has occurred. If an error logging option is specified, then the SQL for all individual cases where there are multiple values per cell will be logged.
The SQL commands used to extract data from the input file for each output table cell can be logged to a file.
As an intermediate step in the crostabbing process, data are converted to a SQLite table. By default, this table is created in memory. However, it can optionally be created on disk, and preserved so that it is available after the crosstabulation is completed.
There are no inherent limits to the number of rows or columns in the input or output files. (So the output may exceed the limits of some other software.)
Input and output file names, and column names in the input file that are to be used for row headings, column headings, and cell values are all required as command-line arguments. If any required arguments are missing, an exception will be raised, whatever the error logging option.
Data rows are sorted alphanumerically by the row headers and column headers are sorted alphanumerically in the output.
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
File details
Details for the file xtab-1.1.0.tar.gz
.
File metadata
- Download URL: xtab-1.1.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27770220923c7ac2faa3a0b5deddd28a603222272f6959ef7d7d1e6b6939526a |
|
MD5 | 71518615d0d7d0e071cf26a7ec682014 |
|
BLAKE2b-256 | 2dd950982e73ac893b8c65140559d4386e0f0c48318055bcc98227dcfb6ee202 |