This content originally appeared on DEV Community 👩💻👨💻 and was authored by Sayem Hoque
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"]
This content originally appeared on DEV Community 👩💻👨💻 and was authored by Sayem Hoque
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.

APA
MLA
Sayem Hoque | Sciencx (2023-02-15T19:30:17+00:00) Python One-Liners #1: Create dictionary from csv file. Retrieved from https://www.scien.cx/2023/02/15/python-one-liners-1-create-dictionary-from-csv-file/
" » Python One-Liners #1: Create dictionary from csv file." Sayem Hoque | Sciencx - Wednesday February 15, 2023, https://www.scien.cx/2023/02/15/python-one-liners-1-create-dictionary-from-csv-file/
HARVARDSayem Hoque | Sciencx Wednesday February 15, 2023 » Python One-Liners #1: Create dictionary from csv file., viewed ,<https://www.scien.cx/2023/02/15/python-one-liners-1-create-dictionary-from-csv-file/>
VANCOUVERSayem Hoque | Sciencx - » Python One-Liners #1: Create dictionary from csv file. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/15/python-one-liners-1-create-dictionary-from-csv-file/
CHICAGO" » Python One-Liners #1: Create dictionary from csv file." Sayem Hoque | Sciencx - Accessed . https://www.scien.cx/2023/02/15/python-one-liners-1-create-dictionary-from-csv-file/
IEEE" » Python One-Liners #1: Create dictionary from csv file." Sayem Hoque | Sciencx [Online]. Available: https://www.scien.cx/2023/02/15/python-one-liners-1-create-dictionary-from-csv-file/. [Accessed: ]
rf:citation » Python One-Liners #1: Create dictionary from csv file | Sayem Hoque | Sciencx | https://www.scien.cx/2023/02/15/python-one-liners-1-create-dictionary-from-csv-file/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.