Skip to main content

csv_fix

PyPI version Python versions Build Status

Instruction

This script uses state machine to fix maleformed csv file.

Usage: csv_fix.py [Options] <filename>
Options and arguments:
  [-h/--help]: Show this message.
  [-s]: Define sperator. Defaults to comma.
  [-q]: Define text qualifier. Defaults to auto detect.
  [-t]: Trim white space at the beginning and end of each field. Defaults to double quote.
  [-z]: (Being constructed) Specify timezone for time fields. Defaults to server timezone. Can also be Asia/Chongqing etc.
        For standard timezone names, refer to: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  [-k]: Skip errors and continue parsing following lines.
  <filename>: csv file name.

Examples

# Input from stdin
cat test_case.csv | csv_fix
# Input from file
csv_fix -t test_case.csv

The processed output will be written to stdout.

Features

Fix Malformed CSV

Try to fix the format whenever possible. You can find test cases in ./tests/.

The script follow this state machine to fix possible errors:

CSV State Machine

Trim White Space

For fields that begin/end with white space can be stripped by specifying -t.

echo -n ' red,	yellow,green ,"red	"' | csv_fix -t
# Output: "red","yellow","green","red"

Customize Seperator

Seperator can be customized. Specify seperator by -s.

echo -n 'A 27" monitor|"This should be good.|"|"' | csv_fix -s '|'
# Output: "A 27"" monitor"|"This should be good.|"|""

Customize Qualifier

Qualifier can be customized. Specify qualifier by -q.

echo -n "'hello, what's up!','Not bad!'" | csv_fix -q "'"
# Output 'hello, what''s up!','Not bad!'

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csv_fix-0.3.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csv_fix-0.3.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file csv_fix-0.3.0.tar.gz.

File metadata

  • Download URL: csv_fix-0.3.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for csv_fix-0.3.0.tar.gz
Algorithm Hash digest
SHA256 87b4c6a619b648aafdaa4a4a17fa176d5b88def5f825b76fdfbf0c7102b50935
MD5 bbedd462b1383e77c53c461c1675059f
BLAKE2b-256 83c702e7aeb658e62857df4a54892c1fca88a8b8be669b5cf1955f7a11a518cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for csv_fix-0.3.0.tar.gz:

Publisher: publish.yml on zhangyaoxing/csv_fix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file csv_fix-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: csv_fix-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for csv_fix-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00b54b4d415bf34c42411532ae9882894bd4e5a10647bfb8bb989aae15aefbd7
MD5 91d420a22c4201f5021975d9699e685d
BLAKE2b-256 b4da98d8d25fb5c15045289e8878b1bee9c4e52afbd4c38ef5f586ecbc676a3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for csv_fix-0.3.0-py3-none-any.whl:

Publisher: publish.yml on zhangyaoxing/csv_fix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page