Posts

Showing posts from November, 2020

Import CSV Analyse and Parse contents

 Reading a csv file: import csv path1='example.txt' #Reading this into a list reader=list(csv.reader(open(path1), delimiter='\t')) #The reader object takes into one list element #treat this list element like a string and split print(reader[1][0].split(' ')) #It breaks into: ['', '2', '98', '3110111288', '205017830', '2', 'firstname', 'middlename', 'lastname', 'M', 'COMN', '1103:GSMC', 'MUMBAI']   # to read individual elements print(recordreader[6]) returns firstname    #Now we can perform operation which splits the characters into individual elements and perform  operation on them for rec in reader: # print(rec) print(len(str(rec))) for i in range(0,4): recordreader=reader[i][0].split(' ') for j in range(0,9): print(recordreader[j])  #Getting these records into a 2-D list- for rec in reader: # print(rec) print(len(rec)) for...