Python - How to Create Dictionary from CSV data file using column headings
问题 I am trying to create a function that accepts the name of a .csv data file and a list of strings representing column headings in that file and return a dict object with each key being a column heading and the corresponding value being a numpy array of the values in that column of the data file. My code right now: def columndata(filename, columns): d = dict() for col in columns: with open(filename) as filein: reader = csv.reader(filein) for row in reader: if col in row: d.append(row) return d