How to split a list into multiple lists using Python


Updated: February 2, 2023


Learn how to split a list (CSV or Excel list) into multiple lists based on values in a column using a Python Script.

If you deal with data as part of your business, you must have stumbled upon this problem every now and then. Many of you look for a solution in Excel or Google Sheets, but a solution in Python is a lot more convenient, especially when you have access to online spaces like Jupyter Notebooks or Google Colab.

Problem Statement

How to split a list into different lists based on a column in the spreadsheet or a CSV file using Python.


What is the required input to split a list into multiple lists using Python?

A CSV file consisting of all the data you want to split into multiple lists.

What is the output of the Python Script?

  1. Separate Lists as Multiple CSVs.
  2. Single Excel (XLSX) file with Multiple tabs.


Steps to follow in the Python Script

  1. Enter the name of the input file.
  2. Select the column you want to use to split the file.
  3. Select the output format (CSV or XLSX).
  4. If the output format is CSV, look for CSV files named after values in the column used for splitting the file.
  5. If the output format is XLSX, look for an XLSX file with tabs named after values in the column used for splitting the file.


You can get the Python script to split a list into multiple lists.


Another topic of interest for you would be applying formulas to new rows in Google Sheets.


And if you like topics like these, you would love to know how to guess genders using Google Sheets and APIs.


Output Samples

CSV: Multiple CSV files, one for each list.

XLSX: A single Excel spreadsheet with multiple tabs, one for each list.

Contact

Thank you. I will respond within 24 hours.

Client Portal | Internal Tools | Web App Builder | Free Website Builder Made with Softr