How to get the data type of a csv file using Python -
i have following data in csv file:--
user_id date num_1 comp_id 101 4/14/2015 1 21 102 5/12/2014 11 1 each column has type.
i want extract , manipulate columns has int data type.
not sure why following code not working.
import csvkit file_name ='file.csv' open(file_name,'r') f: reader=csvkit.reader(f) header = reader.next() items in header: if type(items) == int: print row i not getting output when run this.
you can read string , typecast int
converting string int
def str2int(str): try : return int(str) except : # handle exception correctly print "error in str2int()" print str2int("100") print type(str2int("100"))
Comments
Post a Comment