clevercsv-code - Generate Python code to import a CSV file

clevercsv code [-e ENCODING | --encoding=ENCODING]
               [-n NUM_CHARS | --num-chars=NUM_CHARS] [-p | --pandas] <path>

Generate Python code for importing a given CSV file. This is especially useful if you don't want to repeatedly detect the dialect of the same file. Simply run:

clevercsv code your_csv_file.csv

and copy the generated code to a Python script.

-h, --help

show this help message and exit

-e, --encoding

The file encoding of the given CSV file is automatically detected using chardet. While chardet is incredibly accurate, it is not perfect. In the rare cases that it makes a mistake in detecting the file encoding, you can override the encoding by providing it through this flag. Moreover, when you have a number of CSV files with a known file encoding, you can use this option to speed up the code generation process.

-n, --num-chars

On large CSV files, dialect detection can sometimes be a bit slow due to the large number of possible dialects to consider. To alleviate this, you can limit the number of characters to use for detection.

One aspect to keep in mind is that CleverCSV may need to read a specific number of characters to be able to correctly infer the dialect. For example, in the ``imdb.csv`` file in the GitHub repository, the correct dialect can only be found after at least 66 lines of the file are read. Therefore, if there is availability to run CleverCSV on the entire file, that is generally recommended.

-p, --pandas

By default, this command writes a small Python script to import the CSV file as a list of lists. By enabling this option the script will be written such that the file will be read as a Pandas DataFrame instead.


Path to the CSV file

Part of the CleverCSV suite

2023-09-24 Clevercsv 0.8.2