Coding / Programming Videos

Post your favorite coding videos and share them with others!

Splitting a List into Multiple Lists – Be Nimble – Medium

Source link

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
Split a spreadsheet into different spreadsheets based on a column in the spreadsheet.

Input
A CSV file consisting of all data.

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

Steps
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.

In case you’re interested in this script, developed using Python, just reach out!

Output Samples

CSV: Multiple CSV files, one for each list.

Enter file to be split: List.csv

Select the index corresponding to the column you want to use to split the file:
0 - Customer ID
1 - Name
2 - Email
3 - Address
4 - Domain
5 - Owner

Select the index: 5

File List.csv will be split using Owner as splitter.

Output Format:
0 - CSV
1 - XLSX
Pick the output file type: 0

Input file List.csv will be split into multiple CSVs named as:
Archie.csv
Betty.csv
Veronica.csv

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

Enter file to be split: List.csv

Select the index corresponding to the column you want to use to split the file:
0 - Customer ID
1 - Name
2 - Email
3 - Address
4 - Domain
5 - Owner

Select the index: 5

File List.csv will be split using Owner as splitter.

Output Format:
0 - CSV
1 - XLSX
Pick the output file type: 1

Input file List.csv will be split into multiple tabs in Output.xlsx with the following sheet names:
Archie
Betty
Veronica

This blog post was originally published here at sardamit.com — a blog where I publish my learnings from Data & Analytics Consulting engagements with Small & New Businesses.

Source link

Bookmark(0)
 

Leave a Reply

Please Login to comment
  Subscribe  
Notify of
Translate »