All posts
    Guideshow to split a large csv file into multiple files

    How to Split a Large CSV File Into Multiple Files: 6 Methods Ranked by File Size (2026)

    Split a large CSV into multiple files the right way: by row count, by column value, or by size. Command-line, Python, and no-code methods ranked for huge files.

    November 16, 202614 min readCarbonApps Team

    Most CSV-splitting tutorials hand you a one-line pandas snippet and call it done. That snippet will load the entire file into RAM before it writes a single row, and it will happily slice a quoted field in half if a comma or newline falls on the wrong side of your cutoff. The method that actually works depends almost entirely on how big the file is and whether it has a header, not on which language you happen to prefer.

    Below are six real methods, ranked by the file size each one is actually good for, plus the edge cases that quietly corrupt output if you skip them.

    First decide HOW you want to split (it changes everything)

    Before picking a tool, pick a splitting strategy. "Split this CSV" usually means one of three different jobs, and each one needs different code.

    By row count (every N rows)

    This is the default most people want: cut a 5 million row file into chunks of 500,000 rows each. It is the simplest strategy and the one every command-line and Python method below supports natively.

    By file size (each chunk under X MB)

    Useful when the constraint is a hard byte limit, such as an upload cap, an email attachment limit, or a downstream system that rejects files over a certain size. Row count is irrelevant here; only bytes matter, and rows near a boundary need care so you don't cut one in half.

    By a column value (one file per group)

    Instead of arbitrary chunks, you group rows that share a value, for example one file per region, per customer, or per date. This is a fundamentally different operation (a group-by, not a slice) and it is the one place a spreadsheet genuinely cannot compete with a few lines of Python.

    Why the header row is the detail everyone forgets

    If your CSV has a header row, every split file needs that same header or the downstream tool reading the split files will treat the first data row as column names. The command-line split utility has no concept of a header, it just cuts lines, so the header ends up only in the first output file unless you re-add it. This single detail is the most common reason a "successful" split produces unusable files.

    The fastest method for huge files: the command line (split)

    For files in the tens of millions of rows, nothing beats the Unix split utility for raw throughput. It streams the file rather than loading it, so memory use stays flat regardless of file size, per the GNU coreutils split documentation.

    Splitting by lines with split -l on macOS/Linux

    split -l 500000 bigfile.csv chunk_ --additional-suffix=.csv
    

    This cuts bigfile.csv into files of 500,000 lines each, named chunk_aa.csv, chunk_ab.csv, and so on.

    Re-attaching the header to every output file

    split does not know about headers, so you have to add the header back manually:

    header=$(head -1 bigfile.csv)
    tail -n +2 bigfile.csv | split -l 500000 - chunk_
    for f in chunk_*; do
      sed -i "1i $header" "$f"
      mv "$f" "$f.csv"
    done
    

    This strips the header, splits the body, then prepends the header back onto every chunk.

    Splitting by size with split -b

    split -b 50m bigfile.csv part_ --additional-suffix=.csv
    

    This guarantees every file (except possibly the last) is 50MB. The tradeoff: split -b cuts at a byte boundary, not a line boundary, so it can and will slice a row in half mid-line. Only use -b on files where a partial final row in each chunk is acceptable, or pair it with a post-processing pass that trims incomplete lines.

    The Windows equivalent with PowerShell

    Windows has no built-in split, but PowerShell's Get-Content with -ReadCount streams the file in batches without loading the whole thing, documented in the PowerShell Get-Content reference:

    $header = Get-Content bigfile.csv -TotalCount 1
    $i = 0
    Get-Content bigfile.csv | Select-Object -Skip 1 | ForEach-Object -Begin { $buffer = @() } -Process {
        $buffer += $_
        if ($buffer.Count -eq 500000) {
            $i++
            $header, $buffer | Set-Content "chunk_$i.csv"
            $buffer = @()
        }
    } -End {
        if ($buffer.Count -gt 0) { $i++; $header, $buffer | Set-Content "chunk_$i.csv" }
    }
    

    It's slower than native split but avoids installing WSL or a third-party tool just to cut a file.

    Splitting in Python without blowing up your RAM

    Python is the right call when you need logic during the split: filtering rows, transforming values, or grouping by column. Done wrong, it's also the fastest way to crash a script on a file that command-line tools handle without blinking.

    Why reading the whole file with pandas.read_csv fails on large files

    The classic mistake is df = pd.read_csv('bigfile.csv') followed by a loop that slices the dataframe. read_csv by default loads every row into memory as a dataframe before you write anything, per the pandas read_csv reference. On a file with tens of millions of rows, that single line can consume several times the file's on-disk size in RAM, and on a machine with 4 to 8GB available, it simply fails with a memory error before your split logic ever runs.

    Streaming with the built-in csv module (constant memory)

    The Python csv module reads one row at a time, so memory use stays constant no matter how large the file is:

    import csv
    
    ROWS_PER_FILE = 500000
    
    with open('bigfile.csv', newline='', encoding='utf-8') as infile:
        reader = csv.reader(infile)
        header = next(reader)
        file_count = 0
        row_count = 0
        outfile = None
        writer = None
    
        for row in reader:
            if row_count % ROWS_PER_FILE == 0:
                if outfile:
                    outfile.close()
                file_count += 1
                outfile = open(f'chunk_{file_count}.csv', 'w', newline='', encoding='utf-8')
                writer = csv.writer(outfile)
                writer.writerow(header)
            writer.writerow(row)
            row_count += 1
    
        if outfile:
            outfile.close()
    

    This also correctly handles quoted fields containing commas or embedded newlines, which a naive line-by-line text split does not.

    Chunked splitting with pandas chunksize

    If you still want pandas (for transformations on the way through), use the chunksize parameter, which returns an iterator instead of loading everything at once, also documented in the pandas read_csv reference:

    import pandas as pd
    
    for i, chunk in enumerate(pd.read_csv('bigfile.csv', chunksize=500000)):
        chunk.to_csv(f'chunk_{i+1}.csv', index=False)
    

    Each chunk is read, processed, and written before the next one is pulled in, keeping peak memory bounded to roughly one chunk's size.

    Splitting one-file-per-value with groupby

    When the split criterion is a column value rather than a row count, pandas' groupby is the cleanest approach, per the pandas groupby reference:

    for value, group in pd.read_csv('bigfile.csv').groupby('region'):
        group.to_csv(f'region_{value}.csv', index=False)
    

    For files too large to load whole, combine this with chunksize: accumulate rows per group across chunks and write (or append) once each chunk is processed, rather than loading the full file to group it in one pass.

    No-code and spreadsheet options (and their hard limits)

    For smaller files, you don't need code at all, you need to know where the ceiling is before you hit it.

    Why Excel caps out at 1,048,576 rows

    Excel's worksheet grid has a fixed maximum of 1,048,576 rows and 16,384 columns per the Excel specifications and limits documentation. Open a larger CSV and Excel truncates it silently or refuses to load the rest, with no error that clearly tells you data went missing. If your file is anywhere near a million rows, assume Excel is the wrong tool and use one of the methods above instead.

    Google Sheets and the 10-million-cell ceiling

    Google Sheets measures its limit in cells rather than rows, capping at roughly 10 million cells per spreadsheet according to the Google Sheets limits documentation. A 20-column CSV hits that ceiling at around 500,000 rows, well before Excel's row cap, which makes Sheets a worse fit for wide files even when the row count looks modest.

    ToolHard limitEffective ceiling for a 20-column CSV
    Microsoft Excel1,048,576 rows per sheet~1,048,576 rows
    Google Sheets~10,000,000 cells per file~500,000 rows
    Browser-based CSV splitterVaries, often memory-boundDepends on device RAM

    Browser-based splitters and the privacy tradeoff of uploading data

    Web-based CSV splitter tools are fine for a quick one-off split of non-sensitive data, since no installation is required. The tradeoff is that you are uploading your file to a third party's server to process it. For anything containing customer records, financial data, or personal information, that upload step alone can be a bigger risk than the splitting problem you're trying to solve, so a local command-line or Python method is the safer default whenever the data is sensitive.

    Need this done repeatedly or on a schedule? (mid-article CTA)

    A one-off command is fine when you're splitting a file once. It stops being fine the moment the same export lands in your inbox every week.

    When a one-off command isn't enough

    If you find yourself re-running the same split command or Python script on a recurring export, that's a sign the task has moved from "occasional chore" to "pipeline," and it's worth treating it that way before a copy-paste error corrupts a production dataset.

    Turning your split logic into a reusable script

    Wrap whichever method above fits your file size into a script that takes the input path and chunk size as arguments, log the row counts it produces, and schedule it (cron, a scheduled task, or a lightweight workflow runner) rather than running it by hand each time.

    Explore the carbonapps tools built for data workflows

    If splitting, cleaning, or routing CSV exports is a recurring part of how your team moves data around, it's worth checking whether a dedicated data workflow tool saves more time than maintaining a pile of ad hoc scripts. Browse what's available at carbonapps.com to see if one of our tools fits the recurring version of this problem.

    Choosing the right method: a decision table by file size

    Here are the six methods from this guide, ranked by the file size each one handles best.

    #MethodBest forMemory use
    1Spreadsheet (Excel or Google Sheets)Under ~1,000,000 rows, one-off, non-sensitive dataLoads full file
    2PowerShell streamingWindows, moderate files, no code install neededLow (streamed)
    3Command-line split -l (by row count)1,000,000 to 50,000,000+ rows, Linux/macOSLow (streamed)
    4Command-line split -b (by byte size)Any size, when a hard byte cap matters more than row countLow (streamed)
    5Python streaming with the csv module50,000,000+ rows or recurring jobs needing custom logicLow (constant)
    6Python pandas (chunksize / groupby)Large files needing transformation or group-by splittingModerate (one chunk at a time)

    Under 1M rows: spreadsheet or quick script

    If the file comfortably fits under Excel's or Google Sheets' limits and you're not handling sensitive data, a spreadsheet is the fastest path with zero code. Just confirm the row count first, since "close to a million" often isn't actually under it once you check.

    1M-50M rows: command line split

    This is the sweet spot for split -l or split -b. It's streamed, so memory never becomes the bottleneck, and the throughput of a compiled utility beats an interpreted language on raw line-cutting.

    50M+ rows or recurring jobs: streaming Python

    Once you need filtering, transformation, grouping, or validation as part of the split, or the job runs on a schedule, move to Python's csv module or pandas' chunksize. The slight speed cost buys you logic that split simply can't do.

    Benchmarks: speed vs. memory tradeoffs

    Exact throughput numbers vary heavily by disk speed, CPU, and row width, so treat any specific benchmark you see online with skepticism rather than as a guarantee for your file. The directionally reliable pattern holds across most hardware: command-line split is fastest and lowest-memory for pure row or byte cutting, the csv module is close behind with the flexibility to add logic, and pandas trades some speed and memory for the convenience of dataframe operations mid-split.

    Recombining split files (because you'll eventually need to)

    Someone, probably you, will eventually need the split files back as one file. Plan for it now.

    Concatenating with cat while dropping duplicate headers

    If every chunk has its own header row, a plain cat chunk_*.csv > combined.csv duplicates the header once per chunk. Strip it first:

    head -1 chunk_1.csv > combined.csv
    for f in chunk_*.csv; do tail -n +2 "$f" >> combined.csv; done
    

    Merging in Python

    The same idea in Python, using the pandas read_csv reference's concat pattern:

    import glob
    import pandas as pd
    
    files = sorted(glob.glob('chunk_*.csv'))
    combined = pd.concat((pd.read_csv(f) for f in files), ignore_index=True)
    combined.to_csv('combined.csv', index=False)
    

    For files too large to fit in memory even combined, stream the merge with the csv module the same way you streamed the split.

    Confirming the merged file matches the original

    After merging, verify the row count of the combined file equals the original (minus however many header rows you deduplicated). A quick wc -l combined.csv against the original file catches the most common failure mode: a chunk that got skipped, duplicated, or truncated during the split or merge.

    FAQ

    How do I split a CSV file that's too big to open in Excel? Use the command-line split -l utility (macOS/Linux) or PowerShell streaming (Windows) to cut it into chunks small enough for Excel's 1,048,576-row limit, or skip Excel entirely and process the chunks with Python.

    How do I keep the header row in every split file? Strip the header before splitting the body, then prepend it back onto each output file, either in a shell loop around split or automatically if you're using the Python csv module approach, which writes the header into every new chunk by design.

    What's the fastest way to split a multi-gigabyte CSV? The command-line split utility, used with -l for row count or -b for byte size, is the fastest option since it streams the file and never loads it fully into memory, per the GNU coreutils split documentation.

    How do I split a CSV by the value in a specific column? Use pandas' groupby on that column and write one output file per group, as shown in the Python section above. This is a grouping operation, not a row-count slice, so command-line split can't do it on its own.

    Will splitting a CSV break rows that contain commas inside quotes? Only if you split by raw line cutting without CSV-aware parsing. Tools that split purely on byte or line boundaries, like split -b, can cut a quoted field in half. Using the Python csv module or pandas, both of which understand quoting per RFC 4180, avoids this.

    How many rows should each split file have? There's no universal number. Size each chunk to whatever the downstream system (an import tool, an API upload limit, a teammate's spreadsheet app) can actually handle, then calculate the row count that keeps each file under that ceiling.

    Is it safe to use an online CSV splitter with sensitive data? No, not for customer records, financial data, or anything personally identifiable. Uploading a file to a third-party server to split it means that server now has a copy of your data. Use a local command-line or Python method instead when the data is sensitive.

    Conclusion

    The right way to split a large CSV isn't a single command you memorize, it's a decision tree based on file size, header requirements, and what happens to the data afterward. Spreadsheets handle the smallest files, command-line split handles the middle tier fastest, and streaming Python earns its keep once you need logic or the file outgrows everything else. Whichever method you pick, verify the header made it into every chunk, confirm quoted fields survived intact, and check the row count on the way back out. That's the difference between a split that works and one that quietly breaks something three steps downstream.

    Work with the studio

    CarbonApps is an independent venture studio in Los Angeles.

    Get in touch