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

sayemmh

Sayem Hoque

Posted on February 15, 2023

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
๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
sayemmh
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.

Related

ยฉ TheLazy.dev

About