'How do I make a program that corresponds to a value in a csv file by giving out specific parts of the row in python?

Sorry for the bad Title. How do I make a function in python, that opens a csv file, that is filled with several rows of strings and integers, converts it into dictionaries which can later be used to obtain certain values from certain inputs. If for example the csv is filled with;

Monday, 15, 24, 19

Tuesday, 16, 53, 24

Wednesday, 24, 52, 25

Thursday, 32, 34, 51


And so, if the the input were to be: sales_number(Thursday)

I would get an output of the three of the integers on the same line: [32, 34, 51]

I apologize for my bad English for it is not my first language and I am still quite new. Any kind of help would be appreciated.



Solution 1:[1]

Using csv.reader:

import csv

def sales_number(day):
    with open("the.csv") as f:
        for d, *nums in csv.reader(f):
            if d == day:
                print([int(n.strip()) for n in nums])

sales_number("Thursday")  # prints [32, 34, 51]

If you want to put the data into dictionaries instead of lists, you might find csv.DictReader useful.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Samwise