Sort CSV by Column
Sort CSV rows by one or more columns in your browser. Natural, numeric and alphabetical ordering, with the header row kept in place.
Related tools
All Data tools →This tool runs entirely in your browser. Nothing you enter is sent to our servers, so there is nothing for us to store or see.
About the Sort CSV by Column
Paste CSV and sort its rows by any column, or by several columns at once. Everything runs inside this page on your own device, so nothing you paste is uploaded.
Four orderings are offered because plain alphabetical sorting is wrong more often than people expect. Alphabetical uses proper language-aware comparison, so accented characters sort where a reader expects rather than after z. Natural reads the numbers inside text, so item2 comes before item10 — alphabetically it does not, because 1 precedes 2. Numeric compares values as numbers and tolerates thousands separators, so 1,234 sorts above 999 instead of below it. By length is there for finding the outliers in a column.
Sorting by several columns works the way a spreadsheet does: name them in priority order, and later columns break ties in the earlier ones. The sort is stable, so rows that compare equal keep the order they arrived in — which means you can sort twice to build up a more complex ordering.
Empty cells always sort last, in both directions. An empty cell is missing data rather than a value below every other value, and putting a block of blanks at the top of a descending sort is almost never what anybody wants. The header row is held aside and never sorted into the data.
How to use the Sort CSV by Column
-
Paste your CSV
Paste into the left pane, or drop a .csv file onto it — dropping reads the file locally and never uploads it.
-
Name the columns to sort by
By heading or by position counting from 1. Name several, separated by commas, and later ones break ties in the earlier ones.
-
Choose the ordering
Alphabetical for text, natural when values contain numbers, numeric for figures, or by length to find outliers. Then pick ascending or descending.
-
Copy or download
The sorted CSV appears on the right as you type. Copy it, or download it as a .csv file.
Frequently asked questions
Is my data uploaded anywhere?
No. The sort runs inside your browser and nothing is sent to a server. You can disconnect from the internet once the page has loaded and it will keep working exactly as before.
Why is item10 sorting before item2?
Because alphabetical comparison reads character by character, and the character "1" comes before "2". Switch to natural ordering, which reads the digits inside the text as numbers and puts item2 first. This is the single most common complaint about sorting anything with a number in its name.
Can I sort by more than one column?
Yes. Name them in priority order — "country,city" sorts by country and then by city within each country, exactly as a spreadsheet would. The sort is also stable, so rows comparing equal keep their original order and you can build up an ordering by sorting more than once.
Where do empty cells end up?
Last, in both directions. An empty cell is missing data rather than a value below all others, and a descending sort that begins with a block of blanks is almost never useful. Everything else reverses as you would expect when you switch direction.
Does numeric sorting handle formatted numbers?
Thousands separators and surrounding spaces are ignored, so 1,234 correctly sorts above 999 rather than below it as text comparison would have it. Values that are not numbers at all are placed after every number rather than being treated as zero.