SmartQueryTools

Add Row Numbers to CSV Files Online

Add a row number index column to CSV files directly in your browser. Set the column name and starting number — no upload required.

How to add Row Numbers to CSV files

  1. Drop your file onto the upload area. The row count is shown and the first 200 rows are previewed.
  2. Type a name for the new column. It defaults to row_number.
  3. Set Start at to the first number you want. It defaults to 1, and 0 or a negative number also works.
  4. Click Add Row Numbers. The new column appears as the first column in the preview.
  5. Click Download to save the numbered file in the same format you uploaded.

Your file is processed locally in your browser and is never uploaded. The free limit is 50 MB per file; larger files work if your device has the memory for them.

Worked example

A research team has a batch of survey responses and a second batch already numbered up to 100. They want the new batch to carry on from 101 so the two can be combined later.

Input (CSV)

respondent,country,score,completed
r_8f2a,Ireland,7,true
r_03cd,Portugal,9,true
r_b771,Ireland,,false
r_5e10,Canada,6,true

Settings

  • Column name: response_no
  • Start at: 101

Result

response_norespondentcountryscorecompleted
101r_8f2aIreland7true
102r_03cdPortugal9true
103r_b771IrelandNULLfalse
104r_5e10Canada6true

A new integer column called response_no is placed in front of the existing columns and counts up by one per row from 101. Numbers follow the order of the rows in the file. The other columns are unchanged, including the missing score for r_b771.

Working with CSV files

The number is inserted as the first field on every line, and the header gains the new name at the start. The header line itself is not numbered, so with the default settings the first data line gets 1. That is one less than the line number a text editor shows for it, which matters if you are matching the numbers to error messages that quote line numbers.

Numbering happens after the CSV has been parsed. A line break inside a quoted field does not start a new row, so a multi-line comment is one numbered record, not two. The whole file is then written back with comma separators. Columns that were detected as numbers or dates are rewritten in a standard form, so check any ID columns with leading zeros in the preview. A numbered CSV is also easier to discuss with colleagues. You can refer to record 1,482 in an email or ticket, and anyone with the file can find it with a filter, even after the rows have been re-sorted.

Frequently Asked Questions

Why does the row number not match the line number in my text editor?

The header takes line 1, and quoted fields can span several lines. Row numbers count records, not lines. Set Start at to 2 if you want record numbers to match line numbers in a file with no multi-line fields.

Where does the new column go in the CSV?

It becomes the first column. Use the Columns tool afterwards if you need it somewhere else.

Can I start numbering at 0?

Yes. Set Start at to 0 for zero-based indexes. Any whole number works, including negatives. An empty box or a value that is not a number uses the default of 1, and decimals are cut to a whole number.

In what order are rows numbered?

In the order they appear in the file. The tool does not sort. Sort the file first if you want numbers to follow a date or ID column.

What if I leave the column name blank?

The column is named row_number. Choose a name that is not already used by a column in your file.

Related Tools