Answers for "Convert csv to dictionary in Python"

2

python dictionary to csv

import csv
csv_columns = ['word','matchin']

csv_file = "found.csv"
try:
    with open(csv_file, 'w') as csvfile:
        writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
        writer.writeheader()
        for data in corpus:
            writer.writerow(data)
except IOError:
    print("I/O error")
Posted by: Guest on February-17-2021
1

how to create dictionary in python from csv

input_file = csv.DictReader(open("coors.csv"))
Posted by: Guest on March-01-2020
0

Convert csv to dictionary in Python

pythonCopyimport csv

mydict = {}

with open('csv_file.csv', mode='r') as inp:
    reader = csv.reader(inp)
    dict_from_csv = {rows[0]:rows[1] for rows in reader}

print(dict_from_csv)
Posted by: Guest on August-20-2021

Code answers related to "Convert csv to dictionary in Python"

Python Answers by Framework

Browse Popular Code Answers by Language