How to split a csv file into multiple small files?

Introduction

Easily split a large csv into small files without formula and every output file contains data of the same number of rows . Only upload csv file, Get Results in Seconds. Effortless & Efficient Processing - Try Now!

How to split a csv file into multiple small files

Splitting a large file into small files is not a very simple matter. For example, we will encounter many scenarios like this at work, we might have a csv file that saves order data, and there are millions of lines in it. We need to put this The file is split into several csv files of similar size. How can we do it? Follow these steps and guides to learn more about our product and how to use it effectively.

There are several ways to split a large CSV or Excel file into smaller files:

  • Using Excel: Open the large file in Excel, sort the data on the column that you want to use to split the data, then select and copy the data for each smaller file and paste it into a new workbook. Save each new workbook as a separate file.
  • Using a scripting language such as Python: Use the pandas library to read in the large file, then use pandas methods to split the data into smaller dataframes, and finally write each dataframe to a separate CSV file.
  • Using a data management tool such as SQL: Import the large file into a database, then use SQL queries to split the data into smaller tables and export each table as a separate CSV file.
  • Using a command-line tool such as split: If the large file is a plain text file (CSV), you can split it into smaller files using the "split" command in a terminal. For example, "split -l 20000 largefile.csv splitfile_" will split the largefile.csv into multiple files, each containing 20000 lines, with names like splitfile_aa, splitfile_ab, etc.

If you can use Python, you can split the big csv file into small ones:

Here is a sample Python code using the pandas library to split a large CSV file into smaller files based on a specific column:


import pandas as pd

# read the large csv file into a pandas dataframe
df = pd.read_csv('largefile.csv')

# get the unique values of the column you want to split the data by
column_values = df[column_name].unique()

# loop over the unique values of the column
for value in column_values:
    # create a dataframe for each unique value
    value_df = df[df[column_name] == value]

    # write the dataframe to a new csv file
    value_df.to_csv(f'{column_name}_{value}.csv', index=False)

The best way:Use QuickTran function

  • Visit our website and find the online tool.
  • Open your csv file by clicking the "Choose File" button and selecting the file you want to change.
  • Once the file has been uploaded, you can input the numbers you want to split into. In seconds, you'll split the big csv into small files.
  • You can then download the files and save it to your computer.
Meet our more Transformation tools
Transform data: Text, Date/Time, Location, Json, etc.