convert csv file to list of dictionaries
Use csv.DictReader
:
import csv
with open('test.csv') as f:
a = [{k: int(v) for k, v in row.items()}
for row in csv.DictReader(f, skipinitialspace=True)]
Will result in :
[{'col2': 2, 'col3': 3, 'col1': 1}, {'col2': 5, 'col3': 6, 'col1': 4}]
Another simpler answer:
import csv
with open("configure_column_mapping_logic.csv", "r") as f:
reader = csv.DictReader(f)
a = list(reader)
print a