Skip to main content

tidyCSV.py

CI build mypy tests codecov

Code style: black License: MIT experimental

Tired of having pseudo CSV files full of invalid entries ? Me too, this is my solution.

It has probably occurred to you as it has to me to get this error when reading a csv into Python using pandas.

ParserError: Error tokenizing data. C error: Expected 8 fields in line 7, saw 47

This happens because some lines in your file have more columns than you have in the header, or simply other kind of inconsistencies such as intermediate blank lines or lines containing random tokens.

Fear no more because tidyCSV provides a simple and clear interface to access the semantically coherent chunks of your csv file (if there are any). By default it selects the biggest group found (that is the one containing the most lines).

Maybe I'll add an option to select how many columns you expect, in order to filter the groups according to a preconceived criteria. Eventually I would like this project to become a command line tool as well as having a richer set of features, but It currently serves its purpose so it is not a priority.

Installation

The package has been published to PyPI! You can install it as any other package using pip (I recommend installing it within a virtual environment created in a per project basis).

pip install tidycsv

Otherwise you can install the latest development version using:

pip install git+https://github.com/gmagannaDevelop/tidyCSV.py

Usage

Use the context manager provided at top-level to read an otherwise unreadable csv as follows:

import pandas as pd
from tidycsv import TidyCSV as tidycsv

with tidycsv("your-messy-csv-file.csv") as tidy:
	df = pd.read_csv(tidy)

Now you have a dataframe ready to be used instead of an Exception.

Bugs and feature requests

If you find that tidyCSV is not behaving as you would expect it to, please feel free to open an issue. The same goes for feature requests.

Metadata

Release files for tidycsv 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tidycsv 0.1.2
File Size Uploaded
tidycsv-0.1.2.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tidycsv 0.1.2
File Interpreter ABI Platform
tidycsv-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.6 kB

Release files / tidycsv-0.1.2.tar.gz

Download URL tidycsv-0.1.2.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c5cc40a98d8a4b86b846b6b71db74f52586f069733b41368fd58ba243186703b
BLAKE2b-256 checksum
How to use checksums
277dc454c2e25f8494a734f14640cf86047ea2f537336e7dba3e5aff3b2b6887
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.8 Linux/5.11.0-7633-generic

Release files / tidycsv-0.1.2-py3-none-any.whl

Download URL tidycsv-0.1.2-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c0f6e390956c9e8b98a2d414f915ec5e0004c579bce9d7e6d9bca3594364dc7
BLAKE2b-256 checksum
How to use checksums
6f24476a95794c589fec8465a861afddca1162d0b056ff3c4a6f680f59eb1906
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.8 Linux/5.11.0-7633-generic

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page