A Python script to split large CSV files into smaller files with a specified number of rows. This tool is useful for managing large datasets and breaking them into more manageable pieces.
- Handles filenames with or without
.csv
extension: Automatically appends.csv
if missing. - Customizable row limit: Specify the number of rows per split file.
- Header inclusion: Ensures headers are included in all split files.
- Dynamic output naming: Output files are named with the original row number range they contain, making it easy to track the data.
-
Clone the repository:
git clone https://github.com/sd416/csv-splitter.git cd csv-splitter
-
Run the script:
python split_csv.py -f my_data.csv -n 100 -d /path/to/output
-
arguments:
-
-f FILENAME, --filename FILENAME
- Name of the input CSV file. The .csv extension is optional.
-
-n NUM_ROWS, --num_rows NUM_ROWS
- Number of rows to include in each split file.
-
-d DESTINATION, --destination DESTINATION
- Directory path where the split files will be saved. Defaults to the current directory.
python split_csv.py -f my_data.csv -n 100 -d /path/to/output
The output files will be named:
my_data_1-100.csv
my_data_201-300.csv
.
.
.
.
my_data_501-1000.csv
...