How to Handle Large Datasets
You double-click a data file and Excel spins, freezes, or tells you it cannot open it. Real-world datasets are often far bigger than a spreadsheet can hold, and every beginner hits this wall the first time they grab a serious dataset. This guide is what to do next. It covers how to recognize a "large" dataset, and why you move it into a database. It then lists the handful of real-world quirks that trip everyone up on the way.
- What actually counts as "large"
- Why a database beats a spreadsheet here
- The download quirk: it arrives zipped
- Importing big files (patience and disk space)
- The one step that makes big queries fast: an index
- Sample first, then run on everything
- Aggregate early, and check your data types
First: what counts as "large"?
Put a number on it before you read the list. How many rows does a file need before a spreadsheet stops being the right tool? Your guess is probably too high, and knowing which direction you were wrong in is the useful part.
"Large" is not a vibe, it has real thresholds. A dataset is large enough to need this guide when any of these are true:
- It has more than about a million rows. Excel and Google Sheets stop at 1,048,576 rows. Past that, the file physically cannot fully open. Rows beyond the limit are silently dropped.
- It is hundreds of megabytes to several gigabytes on disk.
- Your spreadsheet freezes, crashes, or says "not enough memory" when you try to open it.
The running example in this guide is a real one: a public dataset of Steam game reviews, recommendations.csv, at about 2 GB and 41 million rows. Excel will not open it. A database will handle it without blinking.
Step 1 — Move it into a database, not a spreadsheet
The single most important move: stop trying to open large data in a spreadsheet. Put it in a database instead. SQLite (via the free DB Browser app) has no practical row limit. The same file that crashed Excel becomes a table you can query in seconds.
This is exactly the create, import, verify workflow from the SQL database guide. The steps are identical for a big file. It just takes longer, which is what the rest of this guide prepares you for.
Step 2 — Expect the download to be zipped (with extras you don't need)
Large public datasets almost never download as a single clean CSV. They arrive as a .zip (often named something generic like archive.zip) that contains several files bundled together. In our example the zip held four files, and we only needed one.
- Right-click the downloaded zip and choose Extract All.
- Open the extracted folder and use only the file you actually need (for us,
recommendations.csv). Ignore the rest.
Step 3 — Import is slow, and the file grows. That's normal.
A 2 GB CSV does not import instantly. Give it time. Two things surprise people, and both are expected:
- The import takes minutes, not seconds. DB Browser may look frozen while it works. Let it finish.
- Your
.dbfile grows to several gigabytes. A 2 GB CSV can produce a multi-GB database. Make sure you have the free disk space before you start: the original CSV plus the database can easily total 4 to 6 GB.
Import the file exactly as in the SQL guide (name the table something ending in _raw, tick "column names in first line"), then press Ctrl+S to save.
Step 4 — Build an index (the step that makes big queries fast)
Picture a phone book, and picture the same names in the order people moved into town. Both hold the same information. Only one lets you find a name without reading every page. Hold that picture, because it is exactly what the next paragraph describes.
An index is a lookup shortcut on a column. Without one, every time you search or join on that column, the database reads all 41 million rows from top to bottom. With one, it jumps straight to the rows it needs. On a small table you never notice. On a big one, it is the difference between instant and unusable.
Build the index once, on the column you will join or filter on most (usually an id):
CREATE INDEX IF NOT EXISTS idx_rec_appid ON recommendations(app_id);
The trap: a function on the join key turns the index off
One refinement that bites even people who know about indexes. An index on title helps a join ON a.title = b.title — but the moment you wrap the key in a function, like ON LOWER(a.title) = LOWER(b.title), the plain index goes unused. That wrapping is the standard move for case-insensitive matching of names. The index sorted the original values, not the lowercased ones. The database silently falls back to comparing every row against every row. Real numbers again: a join of 13,000 rows against 33,000 — small tables by this guide's standards! — is 427 million comparisons without an index, and ran over 30 minutes. The fix is an expression index, built on exactly the expression the join uses:
CREATE INDEX IF NOT EXISTS idx_songs_lower
ON artist_songs (LOWER(primary_artist), LOWER(title));
Same query afterward: seconds. The rule of thumb, upgraded: index not just the column your joins search by, but the exact expression they search by.
Step 5 — Write your query against a sample first
You do not want to wait on 41 million rows every time you fix a typo in your query. Develop against a small slice, then run the finished query on everything.
- Add
LIMIT 1000while you are writing and testing, so results come back instantly. - Or keep a small sample CSV (a few thousand rows) as a separate table for building queries.
Once the query is correct on the sample, remove the LIMIT and run it for real.
Step 6 — Aggregate early, and never dump millions of raw rows to the screen
Asking a tool to display 41 million rows is what freezes it. You almost never want the raw rows anyway, you want a summary. Use GROUP BY to collapse the data to one row per thing you care about:
SELECT app_id, COUNT(*) AS num_reviews, AVG(hours) AS avg_hours
FROM recommendations
GROUP BY app_id;
That turns 41 million review rows into one tidy row per game. Reach for COUNT, AVG, SUM, and GROUP BY before you ever reach for SELECT *.
The quirk that quietly breaks a filter: data types
This one returns no error and no rows. Before reading on, ask yourself what you would do if a filter you were sure about came back empty. If the answer is "check the filter again", the next section is going to save you an afternoon, because the filter is fine.
Before you trust any filter on a big table, look at the actual values first (SELECT * FROM recommendations LIMIT 10;). Large real-world files love to store things in surprising ways. The classic: a true/false column stored as the text 'true' and 'false', not the numbers 1 and 0.
If you assume it is a number and write WHERE is_recommended = 1, it silently matches nothing, and you get a confidently wrong answer with no error message. The fix is simply to match how the data is really stored:
WHERE is_recommended = 'true'
One more honest habit: mind the snapshot
Large datasets are point-in-time snapshots. If you join two big datasets, they may have been collected on different dates (ours were), so they describe the same things at slightly different moments. That is fine, but say so in your write-up. Being upfront about where your data came from and where two sources do not perfectly line up is part of doing the analysis honestly.
Cheat sheet
| Situation | What to do |
|---|---|
| File will not open in Excel | It is over ~1M rows. Move it into a SQLite database. |
| Download is a zip with extra files | Extract, use only the one file you need. |
| Import seems frozen | A multi-GB file takes minutes. Let it finish. Check you have disk space. |
| Joins or filters are slow | CREATE INDEX on the id column, once. |
| Query is slow to iterate on | Develop with LIMIT 1000, then remove it. |
| Tool freezes on results | Do not SELECT * millions of rows. GROUP BY to a summary. |
| Filter returns nothing / weird totals | Check data types. A boolean may be text 'true', not 1. |
When SQLite is not enough
SQLite comfortably handles many-gigabyte files, which covers almost everything you will meet while learning and building a portfolio. If you ever outgrow it, the next tools are DuckDB (built for fast analytics on big files) and pandas with chunksize in Python (read a huge file in pieces). The mindset you just learned carries straight over: put it in a database, index the key, sample while you build, aggregate before you display.
How to Open a Large CSV Without Excel Falling Over
A CSV arrives, it is 1.8GB, and Excel either refuses it or takes nine minutes and truncates it. The instinct is to find a bigger spreadsheet. The better move is to stop trying to look at all of it at once, because almost every question you have can be answered from the first thousand rows plus one aggregate.
What you do, in order: peek, count, sample, aggregate. Only load the whole thing if a real question needs every row.
The short version. You need the columns and the size before you need the data.
Step 1: peek at the top
# Windows PowerShell
Get-Content big.csv -TotalCount 1000 | Set-Content sample.csv
# Git Bash, macOS, Linux
head -n 1000 big.csv > sample.csv
Both read only the beginning, so a 50GB file behaves the same as a 5MB one. Open sample.csv in Excel and you have the column names, the date format, the delimiter, whether the file is quoted, and whether IDs have leading zeros. That is most of what you needed.
Step 2: count the lines
# PowerShell. ReadCount batches the reads, which matters on big files.
(Get-Content big.csv -ReadCount 10000 | Measure-Object -Line).Lines
# Git Bash
wc -l big.csv
Write the number down. It is the only way to prove later that an import loaded everything. Note that a count of lines is not always a count of records: a field containing a newline inside quotes makes them differ, which is one more reason to check totals rather than trusting the eye.
Step 3: take a real sample, not the top
The first thousand rows are not a sample. They are the oldest thousand, or whatever the export sorted by, and any pattern you spot in them may be an artefact of that order. For a genuine look:
-- DuckDB
SELECT * FROM 'big.csv' USING SAMPLE 1000 ROWS;
# pandas, when the file fits in memory
df.sample(1000, random_state=0)
Step 4: aggregate, and bring back only the summary
DuckDB is the shortest route because there is no import step:
SELECT strftime(order_date, '%Y-%m') AS month,
region,
COUNT(*) AS orders,
SUM(amount) AS revenue
FROM 'big.csv'
GROUP BY 1, 2
ORDER BY 1, 2;
That turns millions of rows into a few dozen, which paste into Excel and behave. The setup is in setting up DuckDB.
The pandas equivalent, for a file that does not fit in memory, reads it in pieces:
import pandas as pd
totals = None
for chunk in pd.read_csv('big.csv', chunksize=500_000,
usecols=['order_date', 'region', 'amount']):
g = chunk.groupby('region')['amount'].sum()
totals = g if totals is None else totals.add(g, fill_value=0)
print(totals)
usecols is doing most of the work there. Reading three columns instead of forty is often the difference between fitting in memory and not.
The five tools, ranked by when to reach for them
| Tool | Best at | Cost |
|---|---|---|
| head / Get-Content | Seeing the shape in two seconds | None, already installed |
| DuckDB | SQL over the file as it sits | One install, no import |
| SQLite | Questions you will ask repeatedly | An import, then it is fast forever |
| pandas | Cleaning as part of a pipeline | Memory, unless you chunk |
| A text editor built for size | Eyeballing a broken row | Reading only. No aggregation. |
On that last row: most editors load the whole file into memory and stop being useful in the hundreds of megabytes. Editors that stream, such as EmEditor or glogg, will open a multi-gigabyte file, and they are the right tool for exactly one job, which is looking at the row where an import failed.
The delimiter and quoting checks
- Open the sample in a plain text editor, not in Excel, and look at the raw first line.
- Count the delimiters in line 1 and in a few random lines. They should match. A line with more is an unquoted comma inside a field.
- Look for a byte order mark: the first column header appearing as
idmeans a UTF-8 BOM that some tools will treat as part of the name. - Check the line endings. A file written on Linux and opened in Notepad used to show as one long line. Anything modern handles it, but old importers still do not.
How to apply this to your own work
- Put the peek command in a note somewhere you will find it. It is the single most used command on this page.
- Count rows before and after every import, and keep both numbers in the workbook.
- Install DuckDB the next time a file beats Excel, rather than the third time.
- Ask the source system for an aggregated or filtered export. Half of all large-file work is unnecessary.
- Never sample from the top when you are looking for data quality problems. Bad rows cluster, usually at the end.
The one habit to keep
Look at the file before you load the file. Two commands, ten seconds, and they prevent nearly every import surprise that costs an afternoon.
Do you know the row count of the last extract you built a report on?
This Data Set Is Too Large for the Grid: The Excel Row Limit and What to Do
An Excel worksheet holds 1,048,576 rows and 16,384 columns. Those are 2^20 and 2^14, chosen when the file format was rewritten for Excel 2007, and they have not moved since. When a file has more rows than that, Excel tells you that the data set is too large for the grid and offers you a partial load.
What you do first: find out whether anything was actually lost, because a truncated file that looks complete is a much bigger problem than a warning message.
The short version. If your row count is exactly 1,048,576, you are not looking at all your data.
Check whether you lost rows
- Press Ctrl+End. If the cursor lands on row 1,048,576, treat the file as truncated until proved otherwise.
- Count the source rows without opening it. In PowerShell:
(Get-Content big.csv | Measure-Object -Line).Lines. On a very large file,Get-Content -ReadCount 10000is faster. - Compare that count, minus one for the header, with what landed in the sheet.
- Check the last date or ID in the sheet against the last one in the file. A truncated extract usually stops mid-period, which is the tell in any report built on top of it.
The four routes out
| Route | Effort | Use when |
|---|---|---|
| Aggregate before it reaches Excel | Low | You need totals, not rows. Most cases. |
| Power Query to the Data Model | Low | Staying in Excel, need a pivot over everything |
| DuckDB or SQLite | Medium | Repeated questions, joins, real filtering |
| pandas or Polars | Medium | It is a step in a pipeline you will re-run |
Aggregate first
The honest question is usually not about three million rows. It is about a few hundred summary rows. If the file comes from a system with an export screen, change the export to group by month and category before it lands. That solves the problem permanently and is the option people skip because it means asking somebody.
Power Query to the Data Model
Data, Get Data, From File, From Text/CSV, then Load To and choose Only Create Connection with Add this data to the Data Model ticked. The rows never touch a worksheet, so the million row limit does not apply. Build a PivotTable on the model and Excel aggregates over the whole file.
Two things to know. The model is compressed in memory, so a file that is 2GB on disk may hold in a few hundred megabytes, but 32-bit Excel will still run out at about 2GB of address space regardless. And the grid limit still applies to anything you drill through to.
Query the file where it sits
DuckDB reads a CSV directly with SQL and no import step:
SELECT region, COUNT(*) AS rows, SUM(amount) AS total
FROM 'big.csv'
GROUP BY region
ORDER BY total DESC;
That returns a handful of rows you can paste into Excel. Setup takes minutes and is covered in setting up DuckDB. For anything you will ask more than twice, load it into SQLite instead and keep it.
The column limit, and the reason you hit it
16,384 columns sounds unreachable, and it gets hit by exactly one thing: pivoting a long table wide on a field with too many values. One column per customer, or per day over several years. That is a sign the shape is wrong rather than the limit being tight. Keep the data long and let the pivot do the widening at read time.
Other limits worth knowing before you meet them
| Limit | Value | Where it bites |
|---|---|---|
| Rows per sheet | 1,048,576 | Raw extracts |
| Columns per sheet | 16,384 | Over-pivoted tables |
| Characters in a cell | 32,767 | Free-text notes, JSON blobs |
| Characters shown in a cell | 1,024 | Text that looks cut off but is not |
| Digits of precision | 15 | Long IDs turning into 1.23457E+17 |
| Selected pivot fields | 16,384 items | Very high cardinality pivots |
The 15 digit one catches people constantly: paste a 16 digit account number into a General cell and the last digit becomes zero, permanently. Format the column as Text before pasting, the same defence as in leading zeros on CSV import.
How to apply this to your own work
- Add a row count to every workbook that starts from an import, and compare it to the source count. One cell, one habit.
- When a file gets close to a million rows, stop opening it in Excel at all, even once.
- Ask the system owner for an aggregated export before you build anything clever.
- Learn the Data Model route once. It is fifteen minutes and it removes the limit for most reporting work.
- Format ID columns as Text before any paste, and check the last digits of a few of them afterwards.
The one habit to keep
Never trust a row count you did not compute. The count is the cheapest check in analysis and it catches truncation, duplicated joins and failed filters, all of which look perfectly fine on screen.
Does the workbook you rely on most say anywhere how many rows it started with?
The SQL Kit teaches the exact tools that tame big data: JOIN, GROUP BY, and aggregate functions, with worked examples, practice, and a mock exam. All in your browser, nothing to install.
Or get right into it and learn by writing queries: open SQL Drill, thirteen queries that each add one thing to the last.
Thinking Like an Analyst is 64 pages on the judgment half of the job: defining a metric, telling a report from an analysis, exploring data before you trust it, and saying out loud what your data cannot tell you.
Download the free guide here →Always free. Help keep the lights on: tip the author on Gumroad if it helped.