The CSV Table Viewer program is a command-line application designed to read, display, and manipulate data from CSV (Comma Separated Values) files. The program provides various options for customizing the table output, such as specifying the column separator, displaying specific columns, sorting rows based on a given column, filtering rows by a search string, and limiting the number of displayed rows.
With its simple and intuitive command-line interface, the CSV Table Viewer program provides a convenient tool for users who need to quickly view and manipulate data stored in CSV files.
The program consists of four main modules:
showTable.py: The main script that ties together the other modules, parses command-line arguments, and executes the specified operations.cmd_parser.py: A module responsible for parsing command-line arguments and returning them in a structured format.data_reader.py: A module responsible for reading and cleaning the input CSV data, ensuring it is formatted correctly for further processing.table_formatter.py: A module that handles the formatting and display of the table data, including sorting, filtering, and creating a visually appealing output.
Follow these steps to set up and run the CSV Table Viewer program:
Ensure that you have the following installed on your system:
- Python 3.6 or higher
pandaslibrarytabulatelibrary
To install the required libraries, open a terminal and run the following command:
pip install pandas tabulateTo run the ShowTable utility, open a terminal and navigate to the directory containing the ShowTable files. Then, run the following command:
python3 showTable.py [options] <data_file>where [options] are optional command-line arguments and data_file is the path to the input CSV file.
-s <character>: specifies the separator of the fields (default is ',')-l: outputs only the list of column headers-o <column>: includes only the specified column; can be used repeatedly to include more columns; order matters; (default: lists all columns)-u <column>: sort the table by ordering the specified column in ascending order (default: no sort)-d <column>: sort the table by ordering the specified column in descending order (default: no sort)-m <string>: lists only the rows having at least one element containing the string; multiple appearances are joined by-n <number>: displays only the first specified number of rows of the table
- Display the table with default settings:
python3 showTable.py example.csv- Use a different column separator:
python3 showTable.py -s "|" example.csv- Display only column headers:
python3 showTable.py -l example.csv- Display the two following columns:
python3 showTable.py example.csv -o Phone Name - Sort rows by the Name column in ascending order:
python3 showTable.py -u Name example.csv- Sort rows by the Name column in descending order:
python3 showTable.py -d Name example.csv- Filter rows based on the string "on":
python3 showTable.py -m "on" example.csv- Display the first 10 rows of the table:
python3 showTable.py -n 10 example.csvTo see a test example containing a curated CSV file data, view:
example.csv
For information regarding the API used by the CSV Table Viewer program modules, view:
api_description.md
For infromation regarding the dependencies used in the CSV Table Viewer program, view:
dependencies.md
For infromation regarding the data printed by the CSV Table Viewer program using the example data, view:
example_output.md