I have developed the following .py file for a CSV file with a number of columns and thousands of rows of data. Here is the script I have so far:
infile = open("titanic.csv", "rU")
incsv = csv.reader(infile, delimiter = ',')
outfile = open("titanicOutput.csv", "w")
outcsv = csv.writer(outfile, delimiter = ',')
header = incsv.next()
rowNum = 0
for row in incsv:
(data1, data2, namedata, data4, data5, data6, data7, data8, data9, data10, data11) = row
if '1' in data1:
    rowOutput = [namedata, data2, data4, data5]
    outcsv.writerow(rowOutput)
    rowNum += 1
infile.close()
outfile.close()
Basically the information of namedata column is presented for everyones full name like this "Smith, John". The last name is first followed by first name. I need to separate lastname and firstname and create a column for each in the output - with no comma or quotation marks that already exist. I also need to then present the information with the lastname column in alphabetical order. I know sort() will be used in some capacity to order alphabetically but the splitting I have no idea.
I got this far but have no idea how to split the namedata column - there was one explanation on here I read for a similar problem but it was too complex for me to comprehend in all honesty. Dumbed down explanation would be amazing, thanks!
EDIT: Original File Data (Simplified version for illustration) -
data1   data2   namedata               data4    data5
0         3     Smith, Mr John           m       22
1         1     McMahan, Ms Sally        f       38
1         3     Emmit, Mr Brandon        f       26
Output csv File (Simplified version for illustration) -
lastname    firstname      data2    data4
Emmit       Mr Brandon       3        m
McMahon     Ms Sally         1        f
Smith       Mr John          3        f
Hope that helps!
 
     
     
    