A robust and flexible Command Line Interface (CLI) tool designed to automate the generation of charts from CSV data. It scans directories for CSV files based on configurable patterns, aggregates data, and generates Line or Bar charts using matplotlib.
- Recursive File Scanning: Uses glob patterns (e.g.,
data/**/*.csv) to find files in nested directories. - Flexible Aggregation:
- Group data by specific columns (e.g., Year, Category).
- sum specific columns or calculated totals of multiple columns.
- Chart Types: Supports Line and Bar charts.
- Batch Processing: Define multiple configuration sets in a single JSON file to process different datasets simultaneously.
- Automatic Output: Saves generated charts as
.pngfiles directly alongside the source CSVs.
- Clone the repository (or download the source code).
- Install dependencies:
pip install -r requirement.txt
- Python 3.x
- pandas
- matplotlib
Run the tool from the command line by providing the path to your configuration JSON file:
python main.py --config config.jsonThe tool is driven by a JSON configuration file. The file should contain a list of configuration objects.
| Key | Type | Description |
|---|---|---|
directory |
string |
The glob pattern to search for CSV files. Supports ** for recursive search. |
columns |
string or list |
The column name(s) to plot on the Y-axis. If a list is provided, the tool sums the values of these columns for the plot. |
groupby |
string or list |
The column name(s) to group data by (X-axis). |
chart_type |
string |
The type of chart to generate. Options: "line" or "bar". |
chart_label |
string |
(Optional) Custom label for the chart legend/Y-axis. |
[
{
"directory": "data/finance/**/*.csv",
"columns": ["Income", "Dividends"],
"groupby": "Year",
"chart_type": "bar",
"chart_label": "Total Revenue"
},
{
"directory": "data/expenses/*.csv",
"columns": "Amount",
"groupby": "Category",
"chart_type": "line"
}
]Input File: data/2023_financials.csv
| Year | Category | Salary | Bonus |
|---|---|---|---|
| 2023 | Tech | 50000 | 5000 |
| 2023 | Tech | 52000 | 6000 |
| 2024 | HR | 48000 | 4000 |
Config:
{
"directory": "data/*.csv",
"columns": ["Salary", "Bonus"],
"groupby": "Year",
"chart_type": "bar",
"chart_label": "Total Compensation"
}Result: The tool will:
- Read
data/2023_financials.csv. - Sum
Salary+Bonusinto a calculated total. - Group by
Year(summing the totals for 2023). - Generate a Bar chart named
2023_financials_Year_bar.pngin thedata/folder.