I have splited up a csv files into many smaller ones using code from here(Scroll down to see the full code): https://dzone.com/articles/splitting-csv-files-in-python
files have been successfully split up with its structure preserved,but the headers have disappeared. I suspect something off with the parameters within the pd.read()function.
Please help me have a look at this:
inputfile:
Text Header tag
0 textbody1 Y
1 textbody2 N
2 textbody2 Y
outcome(Structure is still there but my headers are gone in my splitup csv files):
0 textbody1 Y
1 textbody2 N
2 textbody2 Y
Please see below the full script:
import pandas as pd
#csv file name to be read in
in_csv = 'iii_baiterEmailTagged.csv'
#get the number of lines of the csv file to be read
number_lines = sum(1 for row in (open(in_csv)))
#size of rows of data to write to the csv,
#you can change the row size according to your need
rowsize = 10000
#start looping through data writing it to a new file for each set
for i in range(1,number_lines,rowsize):
df = pd.read_csv(in_csv,
header=None,
nrows = rowsize,#number of rows to read at each loop
skiprows = i)#skip rows that have been read
#csv to write data to a new file with indexed name. input_1.csv etc.
out_csv = 'Enronset' + str(i) + '.csv'
df.to_csv(out_csv,
index=False,
header=False,
mode='a',#append data to csv file
chunksize=rowsize)#size of data to append for each loop
Thanks
header=Falsein to_csv.