Skip to main content

A command line tool for CSV file processing

Project description

csv_conv

PyPI version Python versions

Instruction

This script uses state machine to fix maleformed csv file.

Usage: csv_conv.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

cat testcase/test_case_1.csv | csv_conv
csv_conv -t testcase/test_case_1.csv

Features

Quote within Quote

Quotes should be immediated followed by seperator or line end or EOF, otherwise it's not a valid qualifier, and should be escaped. The following format should be fixed (See ../testcase/test_case_1.csv):

"What""s up!","I"m good",I"m also good,"I'm still good"","two quotes" shouldn't make any difference""
./csv_conv.py ../testcase/test_case_1.csv
"What""s up!","I""m good","I""m also good","""I'm still good""","two quotes"" shouldn't make any difference"""

Begin/End with White Space

For fields that begin/end with white space are stripped by default. Otherwise mongoimport type conversion wouldn't work properly (See ../testcase/test_case_2.csv):

 red,	yellow,green ,"red	"
./csv_conv.py ../testcase/test_case_2.csv
"red","yellow","green","red"

If it's not expected behavior, use -t false to cancel it.

Customize Seperator

Seperator can be customized, not necessarily to be ",". Specify seperator by -s. Note that seperators like | needs to be escaped in bash. E.g. (See ../testcase/test_case_3.csv):

"hello"||"This is a test"||"This should be good.||"||""
./csv_conv.py -s '||' ../testcase/test_case_3.csv
"hello","This is a test","This should be good.||""",

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

csv_fix-0.2.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.2.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: csv_fix-0.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 35ebef86e989556cf42f82ff6c0aea331a1d8466241dd4372d692b2f6eb68bc8
MD5 e14012cbfe3c5988f0561eeb7682737b
BLAKE2b-256 2afcf8b827c18b7052c65a472e6178cc44c8a43618b48d5542f912e3457a3e0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for csv_fix-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: csv_fix-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 294ef60129d52fc29ec87c62099a7e266908cd1dec24780de715e139c97d0f6c
MD5 7fa51d0a05483c660108fd87f06007d4
BLAKE2b-256 3e4164a15dbd3d958fc0746a6718f3eb874ee4f5a7552ed4fa861eff93c9fdd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for csv_fix-0.2.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.

Supported by

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