Python One-Liners #1: Create dictionary from csv file
Sayem Hoque
Posted on February 15, 2023
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"]
๐ ๐ช ๐
๐ฉ
Sayem Hoque
Posted on February 15, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.