DEV Community

Sayem Hoque
Sayem Hoque

Posted on

Python One-Liners #1: Create dictionary from csv file

Turn two columns of any csv file into a dictionary:

col1_col2_map = pd.read_csv("cur.csv", dtype=str)[["col1", "col2"]].set_index("col1").to_dict()["col2"]
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
vulcanwm profile image
Medea

nice!