I have a csv file, with simply looks like this:
I have the following code, which reads the csv file, and then can then print/ access information in the CSV file.
import csv
class CsvReader:
with open("Items.csv") as fp:
reader = csv.reader(fp, delimiter=",", quotechar='"')
next(reader, None) # skip the headers
data_read = [row for row in reader]
print(data_read[0])
I get this as the output from the print
['1', '5.99$, '1', 'Blueberry Muffin']
How would I format this into a dictionary, with the headers as the keys and the information as the elements?
For example, the code would output:
{Item #: 1, Price: 5.99, Quantity: 1, Name: Blueberry Muffin}
I referenced and saw a lot of similarities in this post: How do I read and write CSV files with Python?
but couldnt find any more specifics on how to format the output specifically this way, without using something such as pandas, which I am not looking to use.