HomeGuidesHow to Sort a CSV File by Column
Guide

How to Sort a CSV File by Column

4 methods — browser tool, Excel, Google Sheets, and Python

Sorting a CSV by a specific column — alphabetically, numerically, or by date — is one of the most common data prep tasks. Here are four ways to do it.

Method 1: Using Tabular (browser, no software)

  1. 1Go to the Sort Rows tool on Tabular.
  2. 2Upload your CSV or XLSX file.
  3. 3Select the column to sort by.
  4. 4Choose Ascending (A→Z, 0→9) or Descending (Z→A, 9→0).
  5. 5Click Run and download the sorted file.

Tabular detects numeric columns automatically and sorts them numerically (so '10' comes after '9', not between '1' and '2' like text sorting would).

Method 2: Using Excel

  1. 1Open your CSV in Excel.
  2. 2Click any cell in the column you want to sort by.
  3. 3Go to the Data tab and click Sort A to Z (ascending) or Sort Z to A (descending).
  4. 4If prompted, choose whether to expand the selection (to sort all columns together — this is almost always what you want).
  5. 5Save as CSV via File > Save As.

Use Data > Sort (not the quick sort buttons) if you want to sort by multiple columns — for example, sort by Last Name, then by First Name for ties.

Method 3: Using Google Sheets

  1. 1Import your CSV into Google Sheets (File > Import).
  2. 2Click the column header you want to sort by.
  3. 3Go to Data > Sort sheet by column [X], A → Z or Z → A.
  4. 4Export as CSV via File > Download > CSV.

Method 4: Using Python (pandas)

  1. 1Install pandas: pip install pandas
  2. 2Run the script below.

python

import pandas as pd

df = pd.read_csv("input.csv")

# Sort by a single column (ascending)
df_sorted = df.sort_values("column_name", ascending=True)

# Sort by multiple columns
# df_sorted = df.sort_values(["last_name", "first_name"], ascending=[True, True])

df_sorted.to_csv("output.csv", index=False)

Add na_position='last' to sort_values() to push blank cells to the bottom rather than the top.

Frequently asked questions

Why are numbers sorting incorrectly (e.g. 10 before 9)?

This happens when a numeric column is stored as text. '10' comes before '9' alphabetically because '1' < '9'. To fix this, ensure the column contains actual numbers, not text. Tabular detects numeric columns automatically. In Excel, check that the column cells show no green triangle (text-stored-as-number warning).

Can I sort by multiple columns?

In Tabular, you can sort by one column at a time. For multi-column sorts, use Excel's Data > Sort dialog (add sort levels), Google Sheets' Data > Sort range > Advanced, or pandas' sort_values() with a list of column names.

How do I sort a CSV by date?

Dates sort correctly if they're in ISO 8601 format (YYYY-MM-DD). Other formats like MM/DD/YYYY sort incorrectly as text. Use Tabular's Find & Replace to standardize date formats before sorting, or use pandas with parse_dates=['date_column'] to parse and sort correctly.

Does sorting change the original row numbers?

Yes — sorting reorders the rows. If you need to preserve the original order as a reference, use Tabular's Add Row Numbers tool first to add an ID column, then sort. You can always re-sort by the ID column to restore the original order.

Ready to try the fastest method?

Sort your CSV or Excel file by any column — alphabetically or numerically, ascending or descending.

Sort Rows — free