Train/Test Split (CSV)
Shuffle a CSV and split it into train and test sets with a seeded ratio.
About this tool
Split a CSV into a training set and a test set at the ratio you choose. The shuffle uses a seed (default 42), so the same file, ratio and seed give the same split every time. The rows are not stratified by class.
How to use
How it works
Row order is shuffled with a seeded generator, then the first round(rows × ratio) rows become the test set and the rest the training set. At least one row goes to each set. The ratio must be strictly between 0 and 1, and the file needs two or more rows.
Worked example
7 rows, 30% test, seed 42
- Input
- x,y,grp with 7 data rows testRatio 0.3, seed 42
- Output
- trainRows 5, testRows 2 test rows: x=4, x=2 train rows: x=1, 6, 7, 3, 5
- Walkthrough
- round(7 × 0.3) = round(2.1) = 2 rows go to the test set. A different seed would pick different rows.
Limitations
- Simple random split. It does not stratify by class label or keep groups together.
- Two sets only: no validation split (use the train/val/test size calculator for planning).
- Large files depend on your device's memory.
Questions
How do I split a CSV into train and test sets?
What does the seed do?
Does it stratify?
What is a typical test ratio?
Features
- Seeded and repeatable
- Adjustable ratio
- Train and test CSV output
Related resources
Guides and videos from around the web—opens on YouTube or the publisher’s site.
SQL Tutorial - Full Database Course
freeCodeCamp.org
SQL and tabular data sit next to CSV/JSON data tools.
Watch on YouTubeFinding mean, median, and mode
Khan Academy
Descriptive stats for quick data summaries.
Watch on YouTube
- Fetch API
MDN
How browsers pull remote data into local tools.
- Getting started with JSON Schema
JSON Schema
Validate structured data after converting formats.