Creating a dictionary from a csv file?

后端 未结 16 2365
北荒
北荒 2020-11-22 06:13

I am trying to create a dictionary from a csv file. The first column of the csv file contains unique keys and the second column contains values. Each row of the csv file rep

16条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 06:27

    If you are OK with using the numpy package, then you can do something like the following:

    import numpy as np
    
    lines = np.genfromtxt("coors.csv", delimiter=",", dtype=None)
    my_dict = dict()
    for i in range(len(lines)):
       my_dict[lines[i][0]] = lines[i][1]
    

提交回复
热议问题