Skip to content

Free · Browser-local tools

Sort CSV files by column

Sort CSV rows by text, number or ISO date. Choose ascending or descending order and multiple columns, then download your sorted CSV. Free and browser-local.

Sort CSV

Start with your CSV

Open your file in the CSV editor with this tool already selected. Preview the result before downloading.

  1. Choose a CSV or TSV file.
  2. Choose columns, text/number/ISO date comparisons and order.
  3. Preview and download the sorted CSV or apply with undo.

Free · No signup · File contents stay in your browser. Open files up to 1 GiB with browser storage.

Try a small example

3 records · 3 columns
Illustrative CSV sample data
idnameamount
1Example one12
2Example two24
3Example three18

Amount sorted numerically, highest first

Amount sorted numerically, highest first
idnameamount
2Example two24
3Example three18
1Example one12

Illustrative fictional data. Open the sample to try the tool.

How to sort csv

  1. 1

    Choose a CSV or TSV file.

  2. 2

    Choose columns, text/number/ISO date comparisons and order.

  3. 3

    Preview and download the sorted CSV or apply with undo.

What to expect

Sort by up to 20 columns in priority order. Equal keys keep source order. Blank and invalid typed values stay last in both directions; source cell strings and leading zeros are preserved.

Local files and clear limits

These tools process file contents on your device. The browser workspace accepts files up to 1 GiB and 5 million records, subject to available browser storage and decoded-record limits. This tool's calculations support up to 100,000 records, 2 million cells and 64 MB of text. Download a new copy to keep your result.

Plain answers

Sort CSV questions

How are numeric values, blanks and equal sort keys handled?

Sort by up to 20 columns in priority order. Equal keys keep source order. Blank and invalid typed values stay last in both directions; source cell strings and leading zeros are preserved.

Does my CSV leave my device?

File selection, editing and these task operations run in your browser. Optional recipe assistance, when available, sends your goal and only the column metadata or sample values you explicitly include to its configured provider. Your file is not attached automatically; see Privacy for processing details. Manual editing requires no account or file upload. Download a new copy to keep your result; refreshing restores the original input, not unsaved edits.

Do the editor and task have the same file limits?

The editor opens files up to 1 GiB and 5 million records, subject to browser storage and decoded-record limits. This task supports up to 100,000 records, 2 million cells and 64 MB of decoded text.

Other ways to work with your CSV

Use these local examples when you prefer a script or SQL. They create separate results and explain where their behavior differs from this browser tool.

Sort CSV by a numeric column with Python

Writes ascending numeric amounts, with empty or invalid amounts last and ties in source order. Cell strings, including leading zeros, stay unchanged.

Before you start

  • Python 3.10 or later. Run in a working folder with a backup of your source; output files may be replaced unless opened in exclusive mode.
  • Place input.csv in that folder. Examples use UTF-8, a comma delimiter and a header row. Column-specific recipes use id,label,amount,status,note; adapt names to your file.
Run the complete Python example
python3 - <<'PY'
import csv

with open("input.csv", encoding="utf-8-sig", newline="") as source:
    table = list(csv.reader(source, strict=True))
if not table:
    raise ValueError("Expected a header row")
headers, rows = table[0], table[1:]
if any(len(row) != len(headers) for row in rows):
    raise ValueError("Every record must match the header width")

from decimal import Decimal, InvalidOperation

amount_column = headers.index("amount")
def sort_key(row):
    try:
        value = Decimal(row[amount_column])
        if value.is_finite():
            return (False, value)
    except InvalidOperation:
        pass
    return (True, Decimal(0))

rows.sort(key=sort_key)

with open("output.csv", "w", encoding="utf-8", newline="") as target:
    writer = csv.writer(target)
    writer.writerow(headers)
    writer.writerows(rows)
print(f"Wrote {len(rows)} records to output.csv")
PY

Limits and output

  • CSV has no stored type schema. Python keeps fields as strings until an example explicitly converts a value. These recipes do not add spreadsheet formula protection; import sensitive-looking strings as text in spreadsheets.
  • For literal text sorting, use key=lambda row: row[amount_column]. Text collation differs from the browser. For descending numeric order with blanks last, negate only the finite numeric value rather than reversing the entire result.
  • This recipe retains the parsed table in memory; use a streaming approach for files that do not fit.

Documentation: Python CSV reader and writer

Use DuckDB for CSV sort

Run SQL locally with the DuckDB command line. Read fields as text, then cast only the columns used in calculations.

Before you start

  • Install the DuckDB command-line client using its official installation guide.
  • Run beside input.csv. Named-column examples expect id,label,amount,status,note.
Run DuckDB SQL
duckdb <<'SQL'
CREATE VIEW source AS SELECT * FROM read_csv('input.csv', header = true, all_varchar = true, force_not_null = ['id', 'label', 'amount', 'status', 'note']);
COPY (SELECT * FROM source ORDER BY TRY_CAST(amount AS DECIMAL(18, 4)) ASC NULLS LAST) TO 'duckdb-output.csv' (HEADER, DELIMITER ',');
SQL

Limits and output

  • Adapt column names and casts to your input. DECIMAL(18,4) rounds to four fractional digits; values outside its range become NULL with TRY_CAST. SQL output order is not promised without ORDER BY; equal sort keys need an explicit tie-breaker for a deterministic order.
  • These recipes write ordinary CSV without spreadsheet formula protection.

Documentation: DuckDB CSV options and installation; DuckDB COPY export

Use ClickHouse Local for CSV sort

Use the ClickHouse binary in local mode; no database server or upload is needed for these local file paths.

Before you start

  • Install ClickHouse using its official instructions so clickhouse is on PATH.
  • This explicit example schema is id,label,amount,status,note. Change every column name/type to match your header before running. Use a fresh folder or remove only a previous example output before repeating it.
Run ClickHouse Local SQL
clickhouse local --multiquery <<'SQL'
CREATE TABLE source ENGINE = Memory AS SELECT * FROM file('input.csv', CSVWithNames, 'id String, label String, amount String, status String, note String');
SELECT * FROM source ORDER BY toDecimal64OrNull(amount, 4) ASC NULLS LAST INTO OUTFILE 'clickhouse-output.csv' FORMAT CSVWithNames;
SQL

Limits and output

  • The example loads a Memory table, so it must fit in available memory. All source fields are explicitly String to retain identifiers; numeric casts use fixed scale 4. CSVWithNames writes a header and ClickHouse quoting. Sorting equal keys and un-ordered queries do not guarantee original row order.
  • Output is ordinary CSV without spreadsheet formula protection. A remote ClickHouse server reads its own filesystem; these commands intentionally use local mode.

Documentation: ClickHouse Local and installation; ClickHouse CSV formats