Skip to Content
RowSlice

Free Online CSV Sampler

Take a Sample from a CSV File

An export is far too big to open, and you need a few thousand of its rows to test an import or try a script on. Take the first rows, every Nth row or a random slice, and leave the rest of the file alone.

  • Multi-GB files
  • Never uploaded
  • Free, no sign-up

In short: RowSlice’s CSV sampler makes a small CSV out of a big one. It takes the rows from the start of the file, one row in every so many, a fixed number of rows drawn at random, or a share of them, and writes them to yourfile-sample.csv with the header row on top. It runs in your browser, so the file is never uploaded, and every row is copied as the text it was written in, in the order it was in the file.

This is not the sample CSV generator. This tool needs a file from you, and every row it writes came out of that file — your columns, your values, your data. The sample CSV file generator takes no file at all: it invents customers, orders, employees and products that never existed, for when you need test data that belongs to nobody. If you came looking for a file to download without having one to start from, that is the page you want.

A sample is for the jobs where the whole file is in the way: checking how the date column is written before you trust it, trying a new script on something small enough to read by eye, or loading a staging system with a few thousand real rows instead of every row you have. In each of those the rest of the file costs time and answers nothing. When reading some rows is the whole of the job, you may not need a file at all — the CSV viewer opens the original, pages through it 100 rows at a time and writes nothing.

How to Take a Sample from a CSV

  1. Choose or drag in your CSV file and check the preview of the first rows.
  2. Pick which rows to take: Rows from the start, One row in every so many, Rows drawn at random, or A share of the rows.
  3. Type the number that goes with it — how many rows, how often, or what percentage of them.
  4. Press Take the Sample and download yourfile-sample.csv. The result says how many rows came out and, in the three modes that read to the end, how many rows the file holds.

If your file has no header row, untick First row is a header under Advanced Options. The first line is then treated as data, so it can be picked for the sample like any other row instead of being copied to the top of the result.

The Four Ways to Sample

Sample typeWhat you getWhen to use it
Rows from the startThe first rows of the file, in the order they are in it. The read stops as soon as it has them, so the rest of the file is never read.A look at the shape of a file: the column names, how dates and numbers are written, whether the delimiter is the one you expected.
One row in every NRow 1, then every Nth row after it, to the end of the file.A spread across the whole file. The one to choose when the file is sorted by date, region or ID, where the first rows all come from one part of it.
Rows drawn at randomExactly the number of rows you ask for, every row of the file equally likely to be one of them, chosen in one pass. Fewer only if the file holds fewer rows than that.A sample you are going to measure something on, where taking rows by position would bias the answer.
A share of the rowsClose to that percentage of the rows, not exactly it: every row gets its own chance of being kept.Keeping the sample proportional to the file when you do not know how many rows it has.

Two of those differences matter more than the rest. Rows from the start is the only mode that does not read the whole file — it stops at the last row it needs, which on a large export is the difference between reading a thousand rows and reading all of them. Rows drawn at random is the only mode that holds rows in memory, because it cannot know which rows belong in the sample until the file ends; that is why it is capped at 1,000,000 rows and refuses a larger ask before it starts. The other two write each row as they meet it and hold nothing.

If you do not know how many rows the file has, the CSV analyzer counts them without writing a file. That is also how to turn “about one per cent” into a row count you can ask for outright, which A share of the rows cannot give you.

Why a Random Sample Is Repeatable

Random here does not mean different every time. The two modes that use chance — Rows drawn at random and A share of the rows — draw their numbers from a seeded generator, set to 42 under Advanced Options, and nothing else feeds into the choice. The same file, the same mode and number, and the same seed give a byte-identical sample on every run, on any machine.

That is what makes a sample worth putting in a bug report. Rather than attaching a file, the report can name the file, the mode, the number and the seed, and whoever picks it up rebuilds the same rows, the one that broke the import included. Change the seed and you get a different draw of the same size out of the same file, which is how to check that a result was not an accident of one sample.

A Sample Keeps the File’s Own Order

Rows come out in the order they were in the file, in all four modes. That is obvious for the rows from the start and for one row in every so many. It is worth saying for a random sample, because the method that picks the rows does not produce them in order: it fills a fixed set of places as the file streams past, replacing rows already in the sample as it goes, and the rows end up in whatever order the places were taken. They are sorted back into file order before a single one is written, so row 4 of the sample is always earlier in the file than row 5, and the sample can be lined up against the file it came from.

Values are not touched either. Each row is written as the exact text it arrived as, so codes keep the leading zeros Excel drops when it opens a CSV, long references keep every digit, and a quoted value holding a comma or a line break comes out quoted the way it went in. The header row is copied from the file’s own first line rather than rebuilt from the column names, and the sample keeps the delimiter and the line endings the original had. Those zeros survive the sample and are lost at the next step if the sample is opened in Excel, so when the rows are going into a spreadsheet, write the sample out as an .xlsx workbook instead of double-clicking the CSV.

Sampling Is Not Splitting

The two get confused because both turn one large file into something smaller. The difference is what happens to the rows you did not ask for: a sample leaves them behind, written nowhere, while splitting a CSV keeps every one of them.

ToolWhich rows it keepsWhat you end up with
Take a sampleSome of them, chosen by position or by chanceOne smaller file. The rows that were not chosen are not written anywhere.
Split a CSVAll of themSeveral files, split by rows, size or number of parts, with the header repeated at the top of each.
Filter CSV rowsEvery row that matches the conditions you setOne file of the matching rows, and a second file of the rest if you ask for it.

So: split when every row still has to exist somewhere, which is usually an import that will not take a file this large — splitting a CSV to fit an import limit lists the published limits. Sample when the rows you leave out are of no further use to you. And if the rows you want have something in common — one country, one status, the orders above an amount — that is neither job: filtering keeps exactly those rows and nothing else.

Making a Test File for an Import

The common reason to take a sample is to have something small enough to push through an import, a script or a staging system without waiting for the whole export. A sequence that saves a second round:

  1. Analyze the file first. It reports the row count, the column names, the delimiter and the encoding, which is what you need in order to choose a sample size rather than guess one.
  2. Take the sample with One row in every so many rather than with the rows from the start, unless you already know the file is unsorted. The rows at the top of an export sorted by date all come from the same stretch of time, and they can miss the empty columns, the accented names and the over-long values that turn up further down.
  3. Run the validator over the full file, not only over the sample. It reports broken rows, unclosed quotes, a wrong encoding and repeated IDs wherever in the file they are, and those are exactly what a sample of a few thousand rows can leave behind.
  4. Import the sample. Anything the import rejects at this size is something you would rather find now than an hour into loading the whole file.

One thing a sample cannot do is make the data safe to hand out. Every row in it is a real row, with real names and real addresses in it, so it falls under the same rules the original does. When the test system is one the real data must not reach, the sample CSV file generator is the other half of this pair: the same shape of file, the same awkward values if you ask for them, and no real person in any row of it.

Last updated .

FAQ

Frequently Asked Questions

Is this the same thing as the sample CSV generator?

No — they are opposite jobs, and it is worth checking which page you are on. This tool takes rows out of a CSV you already have, so every row in the result is your own data. The sample CSV file generator takes no file at all and invents rows: made-up customers, orders, employees or products. Use this page to cut a real export down to a usable size; use the generator when you need a test file and have no data you are allowed to use.

How many rows can a random sample have?

Up to 1,000,000. Rows drawn at random is the one mode that has to hold rows in memory: which rows end up in the sample is not settled until the last row of the file has been read, so the sample itself sits in the tab until then. Ask for more than that and the tool says so before it starts, rather than running out of memory halfway. The other three modes hold no rows at all — they write each one as they meet it — so One row in every ten will give you ten million rows out of a file with a hundred million in it.

Will the same file give me the same random sample twice?

Yes. The two modes that use chance — Rows drawn at random and A share of the rows — draw from a seeded generator set to 42 under Advanced Options, not from anything that changes between runs. The same file, the same mode and number, and the same seed produce a byte-identical sample every time and on any machine. That is what makes a sample usable in a bug report: “orders.csv, 10,000 random rows, seed 42” is enough for whoever picks it up to rebuild exactly the rows you were looking at. Change the seed for a different draw of the same size.

Why did a 1% sample not come out at exactly 1%?

Because A share of the rows gives every row its own one-in-a-hundred chance rather than counting out a fixed number. Over a large file the result lands close to one per cent, but it will not land on it, and the same file with a different seed lands somewhere else nearby. When the count has to be exact, choose Rows drawn at random instead: that mode gives you exactly the number you typed, unless the file holds fewer rows than that, in which case you get all of them.

Which rows does “one row in every 10” take?

Rows 1, 11, 21, 31 and so on, counted from the first data row — the header row is not counted. It starts at the top of the file rather than at row 10 so that the first row of the sample is the first row of the file, which is the row you are most likely to check it against. This mode reads the file to the end, so the rows it takes are spread across all of it.

Does taking a sample change any of my values?

No. Each row is copied as the exact text it was written in, so 00742 keeps its leading zeros, a 16-digit reference keeps all 16 digits, and a quoted value with a comma or a line break inside it comes out quoted the way it went in. The header row is copied from the file’s own first line rather than rebuilt from the column names, and the sample keeps the delimiter and the line endings the original had.

Is there a limit on the size of the file I can sample?

The tool sets no row limit and no size limit of its own. The file is read about 4 MB at a time instead of being loaded whole, and three of the four modes remember nothing from one row to the next, so memory stays flat whether the file holds 10,000 rows or 500 million; only a random sample grows, and only with the number of rows you asked for. What you need is free disk space for the result, inside the allowance your browser gives one site — about 10 GB in Firefox — and the sample is at most the size of the file it came from.

Does taking the rows from the start tell me how long the file is?

No, and that is the trade. Rows from the start stops as soon as it has the rows you asked for and never sees the rest, which is the whole point of that mode: taking 1,000 rows off a 40 GB export costs 1,000 rows of reading, and the result says as much — that it took the first rows and left the rest of the file unread. The other three modes read to the end, so the count they report is the file’s real number of data rows. To count the rows without writing a file at all, use the CSV analyzer.

Is my file uploaded anywhere?

No. The file is read from your disk by code running in your own browser, and the sample is written to your browser’s own private storage on the same disk, so a file of real names, addresses or salaries stays on the machine it is already on. Once the page has loaded it keeps working with the connection switched off. There is no account and no copy on any server, and results left behind are removed after six hours the next time you use a tool.

Guides

More Tools

More CSV Tools

CSV Analyzer

Count the rows, list the columns and profile the values in a CSV too big to open.

CSV Viewer

Page through and search a CSV that is far too large for Excel, without uploading it.

Compare Two CSV Files

See what was added, removed and changed between two exports, matched on an ID column.

Sample CSV File Generator

Download realistic test CSV files from 10 rows up to 20 GB, with messy values on request.

Split CSV into Multiple Files

Cut a CSV that Excel refuses to open into multiple files by rows, size or number of parts.

Split CSV by Column Value

One file for every store, region, client or status — straight from a huge export.

Filter CSV Rows

Keep only the rows you need — by value, text match or number range — from a file of any size.

Merge CSV Files

Combine multiple CSV files into one, lining up columns by name, even when the result is too big for Excel.

Remove Duplicates from CSV

Delete repeated rows from millions of records, comparing whole rows or chosen columns.

Convert CSV to Excel

Make a real .xlsx file without losing leading zeros, long IDs or turning codes into dates.

Convert CSV to JSON

Turn a CSV into a JSON array or NDJSON, with every value kept exactly as written.

Convert JSON to CSV

Flatten a JSON array or NDJSON export into a spreadsheet-ready CSV.

CSV Validator

Find the broken rows, bad quotes, wrong encoding and duplicate IDs before an import fails.

Convert CSV to UTF-8

Repair garbled characters like é by converting to UTF-8, and switch semicolons to commas.