I have to write a python script that splits this numbers.csv.gz into 10 new file
ID: 3889172 • Letter: I
Question
I have to write a python script that splits this numbers.csv.gz into 10 new files the files are based off of column B where column has ordered integers 1-10. I need to write a python script to break that file into 10 other files based off that column B so all those with 1 in the row belong to one file those with two belong to another and so forth.
This is all based off of column
Explanation / Answer
To split the big csv files python has a very good module 'pandas'.Just install that and it's a 4 line code.
Just install pandas dependencies.
import pandas as pd
csv = pd.read_csv('numbers.csv', sep=',', header=0, skipinitialspace=True)
# header=0 header is on the first line
# skipinitialspace is set to True because if example data has spaces after commas
for i in range(1,11):
csv_col = csv[csv['B'] == i]
csv_col.to_csv('col'+ i +'num.csv', index=False, sep=',')