Python select specific column values from enumeration list based on column index list -


in below code: reading file, fetching header row, looking specific header columns , storing indices. iterate through rest of rows , want value of indices.

    import csv        def csvreader(csvfilename):     counter = 10     keymap = []     header = ["test1","test2"]     open(csvfilename,'r') f:         reader = csv.reader(f,skipinitialspace=true)         firstline = true         print(reader)         row in reader:             if counter > 0 , firstline == true:                 print(list(enumerate(row)))                 indexes =[i i, j in enumerate(row) if j in header]                 print(indexes)                 firstline=false                 counter = counter - 1             elif counter > 0:                 = dict(zip(header, map((lambda str: row[i] in indexes) ,row)))                 print(a)                 print('test')                 counter = counter - 1         return keymap    if __name__ == '__main__':     csvreader("c:/test.csv") 

folks- response. fixed it. changing below:

a = dict(zip(header, map(str, (row[i] in indexes)))) 

but better solutions, please share them.


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -