Train/Test Split (CSV)

Shuffle a CSV and split it into train and test sets with a seeded ratio.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

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

1
Step 1
Paste the CSV or drop a file.
2
Step 2
Set the test ratio (default 0.2) and the seed (default 42).
3
Step 3
Press Process and copy the train and test CSVs.

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?
Set the test ratio and seed, then press Process. You get a train CSV and a test CSV.
What does the seed do?
It makes the shuffle repeatable. Using the same seed gives the same split.
Does it stratify?
No. Class proportions can differ between the sets, especially with small or imbalanced data.
What is a typical test ratio?
0.2 or 0.3 are common choices.

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 YouTube
  • Finding mean, median, and mode

    Khan Academy

    Descriptive stats for quick data summaries.

    Watch on YouTube