๐งน Data Prep ยท 7 min read
How to Remove Blank Rows From a CSV: 4 Free Methods (2026)
The fastest fix is one line: awk 'NF' file.csv deletes every truly empty line. For blank rows sitting among real data, or rows that contain nothing but commas, use a filter in Excel or Google Sheets so you can see exactly what disappears before you commit. Whichever route you take, strip whitespace first, because a cell holding a single space or a non-breaking space is not blank to a parser, no matter how empty it looks on screen.
What Counts as a "Blank" Row
There are three cases and they need different tools.
The first is a genuinely empty line: a line break with nothing between it and the next. It has no fields at all, and it is what most people mean by a blank row.
The second is a row of commas, something like ,,,. RFC 4180 says every record carries the same number of fields, so this line is a valid record whose fields happen to be empty. A parser reads it as a row with four empty values, not as a gap.
The third is the sneakest: a row where a cell holds a space, a tab, or a non-breaking space. Excel's ISBLANK() returns FALSE for all three, so your "remove blanks" step walks straight past them and they reappear the moment the file is re-parsed.
Knowing which one you have is most of the job. The four methods below are ordered from most interactive to most automated.
Method 1: Excel (Filter and Delete)
The filter route is slow but visible, which matters when you are not sure how many rows will go.
- Select the whole data range, then go to Data > Filter.
- Click the dropdown on your most reliable column, say an ID or a name.
- Untick Select All, then tick Blanks and click OK.
- Select the visible row numbers, right-click, and choose Delete Row.
- Clear the filter and save the file as CSV.
One warning. If any formula in the sheet points at a specific row, deleting rows shifts every reference below the gap. Paste those formulas as values first, or re-check them after saving.
Excel's Go To Special > Blanks command is the other built-in option, but it only reacts to cells that are truly empty. A formula that returns an empty string, or a cell holding a space, is left alone, which is exactly the trap described above.
Method 2: Google Sheets
Sheets uses the same idea, with a live count that makes it easier to trust.
- Go to Data > Create a filter.
- Click the filter icon in the header of a key column.
- Under Filter by condition, choose Is empty.
- Check the row count shown in the filter panel, then delete the visible rows.
- Remove the filter and download as CSV through File > Download.
That count is worth a glance. If Sheets reports four rows and you expected four hundred, the blanks are not where you think they are.
Method 3: The Command Line
For empty lines only, awk is a one-liner. The condition NF means "print the line if it has at least one field", so empty lines fall out:
# delete truly empty lines
awk 'NF' customers.csv > customers_clean.csv
# if the file uses Windows line endings, strip the carriage returns first
tr -d '\r' < customers.csv | awk 'NF' > customers_clean.csvTo catch rows of commas as well, match on the whole line being separators:
# drop lines that contain only commas (and optional spaces)
grep -vE '^[,[:space:]]*$' customers.csv > customers_clean.csvThese are fast and exact, but they are the wrong tool for a row where one column is empty and the rest is full. That row is real data and should stay.
Method 4: Python (pandas)
When the cleaning is part of a repeatable pipeline, pandas expresses the intent in one line:
import pandas as pd
df = pd.read_csv("customers.csv")
# strip surrounding whitespace, then drop rows that are empty in every column
df = df.map(lambda v: v.strip() if isinstance(v, str) else v)
df = df.dropna(how="all")
df.to_csv("customers_clean.csv", index=False)Two details matter here. The map line removes the spaces and tabs that made rows look full, and how="all" tells dropna to remove a row only when every column is empty. Leaving how at its default drops any row with a single missing value, which would quietly delete most of a sparse dataset.
If the blanks are stubborn because of non-breaking spaces pasted in from a web page, pandas' strip() will not catch them, since it does not treat a non-breaking space as whitespace. Replace that character explicitly before the strip step:
df = df.replace("\u00a0", " ", regex=False)Method Comparison
| Method | Catches empty lines | Catches ,,, rows | Catches whitespace cells | Best for |
|---|---|---|---|---|
| Excel filter | Yes | Only if you filter on blanks per column | No | Small files, visual check |
| Google Sheets | Yes | Only per column | No | Browser work, no install |
| awk / grep | Yes | Yes, with a pattern | No | Large files, speed |
| Python pandas | Yes | Yes | Yes, with one extra line | Repeatable pipelines |
Why This Is Worth Doing Properly
A 2016 CrowdFlower survey of 577 data scientists found that 60% of their working time went to cleaning and organising data, with another 19% on collecting it. That is 79% before a single chart or model. Blank rows are a small part of that, but they are the part that most often breaks something downstream: a sort that stops early, an import that fails on a null primary key, or a dashboard that reports a phantom dip because three empty rows landed in the middle of a month.
Excel decides the extent of a data range by finding the last populated cell, so a gap is not cosmetic. It can make Sort or AutoFill finish early and leave later records untouched, which is the usual reason a sort "does nothing" until the gaps are cleared.
If the file came from somewhere messy, blank rows are rarely the only problem. The dirty data cleaning guide covers duplicates, inconsistent dates, and stray delimiters, and the duplicate removal guide handles the next pass.
Frequently Asked Questions
What is the fastest way to remove blank rows from a CSV?
If the blank rows are whole empty lines, one awk command removes them: awk 'NF' file.csv. If the blanks sit among real data, or a row contains only commas, use a filter in Excel or Google Sheets so you can see exactly which rows disappear before you commit.
Why does my CSV still have blank rows after I delete them?
Because the row was not empty. A row written as ,,, has the right number of fields, just with no values in them, and a cell containing a space or a non-breaking space is not blank to a parser. Strip whitespace first, then test for emptiness, or filter on whether the key column is empty rather than the whole row.
How do I remove blank rows in Excel?
Select the data range, go to Data > Filter, click the dropdown on your key column, untick Select All, tick Blanks, then right-click the visible row numbers and choose Delete Row. Clear the filter and the rows are gone. Save as CSV to keep the change in the original format.
How do I remove blank rows in Google Sheets?
Create a filter with Data > Create a filter, click the filter icon on any column, choose Filter by condition > Is empty, and delete the visible rows. Sheets keeps a running count of matching rows in the filter panel, which is a useful sanity check before deleting.
Does deleting blank rows change my data?
Deleting a genuinely empty row changes nothing about the remaining records, but it does shift row numbers, so any hard-coded cell references in formulas move with them. Paste values before you clean if a formula points at specific rows, or the results will drift after the delete.
Why do blank rows break Excel formulas and sorting?
Excel decides how far a range extends by looking for the last populated cell, so a stray blank row can make a sort or an AutoFill stop early, leaving later records untouched. Removing the gaps first is the reason a sort that "did nothing" suddenly works.
Can I remove blank rows without opening Excel?
Yes. The command line handles empty lines with awk or grep, and Python's pandas library drops fully empty rows with dropna. For a file you would rather not upload, those two keep the data on your own machine, which matters when the CSV holds customer records.
Tools mentioned in this guide
Want to go further with AI-powered data work? These tools pair well with NoCodeCSV:
- Stack AI โ if messy exports arrive from the same source every week, an AI workflow can strip whitespace and drop empty rows at ingest, so the cleanup stops being a manual step. Try Stack AI
- Softr โ once the data is clean, a Softr app reads it directly, so nobody re-downloads the CSV and reintroduces the blank rows you just removed. Try Softr
- Toggl Track โ data cleaning is the classic invisible task; timing it once turns "it only takes a few minutes" into a number you can act on. Try Toggl
Some links above are affiliate links โ if you buy through them we may earn a commission at no extra cost to you. Links currently point to each vendor's official page until our dedicated tracking links are registered.
Find the Blank Rows Before They Break Something
Run the free CSV analyzer to see empty rows, mixed formats, and delimiter problems in one pass, before you start editing by hand.
Related reading
Data Cleaning โ other guides that pair well with this one.
Browse all guides in the NoCodeCSV blog.