I have a csv file with 15 columns.I want to read the csv and make a python dictionary that consists of first column as a key and remaining columns as a value in the form of a list.Each key in the dictionary should be a string. But i have no idea to make the all values as a python list.
import csv
mydict = {}
with open('Emissions.csv', mode='r') as inp:
reader = csv.reader(inp)
dict_from_csv = {rows[0]:rows[1] for rows in reader}
print(dict_from_csv)
Try:
dict_from_csv = {row[0]:row[1:] for row in reader}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.