CSV Scripts

Scripts involving the manipulation of CSV Files

csv_to_list_parser.py

This script will transfer a .csv file to dataframe and print (std out) a list. Automatically tries to convert numerical values into floats.

Input:

  • -i : CSV to print

Output:

  • CSV as list

Usage

  • python csv_to_list_parser.py –version

This is the option that show you the program’s version.

  • python csv_to_list_parser.py -h

This can show you some help information.

  • python csv_to_list_parser.py -i <filename.csv>

Runs the program given the specified CSV file.

csv_to_list_parser.main()

Writes CSV to list

dump_csv_stats.py

This script will print (std out) the fieldnames and the number of elements in each fieldname after spited by deliminator

Input:

  • -i : CSV file to search

  • -d : Deliminator to split file by

Output:

  • Fieldnames and number of elements in each fieldname

Usage:

  • python dump-csv-stats.py –version

This is the option that show you the program’s version.

  • python dump-csv-stats.py -h

This can show you some help information.

  • python dump-csv-stats.py -i <filename.csv> -d deliminator

Runs the program with the specified CSV file and deliminator.

dump_csv_stats.main()

Find and print the number of elements in each fieldname

parse_csv.py

This script will print(std out) an array. This array contains the original csv file and add a column at last. Elements in the new last column is the product of the third row and the fourth row, and it will ignore the first row(because it is normally titles for the rows)

Input:

  • -i : CSV to combine

Output:

  • Array containing original CSV file and additional column

Usage

  • python parse_csv.py –version

This is the option that show you the program’s version.

  • python parse_csv.py -h

This can show you some help information.

  • python parse_csv.py -i <filename.csv>

Runs program with specified csv file

quote_csv.py

This script will add double quotes to all values in a csv file. If a value is already quoted, quotes will not be added to that value. If there is quoted text within a value the quoted text will now have two sets of quotes e.g. “”quoted text””.

Input:

  • -i : the path to the original csv file to edit.

  • -o : the path to the output csv file that will contain the edits.

Output:

  • The edited csv file to the path specified in output_file argument.

Usage:

  • python quote_csv.py –version

This is the option that show you the program’s version.

  • python quote_csv.py -h

This can show you some help information.

  • python quote_csv.py -i <filename.csv> -o <output_file.csv>

Runs program with specified file to quote and output file

quote_csv.main(csv_file, output_file)

Quote original CSV file and write contents to specified output file