Time to Code
Read the questions and solve the problems.
We'll cover the following...
Challenging questions❓
To provide you with a headstart, we have attached the dataset file food.csv at the backend, and have read it in a list: data
. Here’s the snippet:
import csvwith open('food.csv', newline='') as f:reader = csv.reader(f)data = list(reader) # contains the data in raw formatprint(data)# Columns you'll deal with in this projectrequired_columns = ['GPA', 'Gender', 'drink', 'exercise', 'fries', 'income', 'sports', 'weight']
We have hard-coded required_columns
: a list containing the columns we’ll need, and leaving out the rest.
Let’s start the fun!
Task 1: Group the data
This task is not as simple as it seems. The data is in the raw format. You can try printing the data
and can see it for yourself. One can’t make any sense out of it. First, we have a list of all the column names. Then, we have a separate list for every student’s response containing values to those columns; keeping a tally of which value corresponds to which column is hectic.
Your first task is to write a function group_values_with_columns
to group the data. By grouping, we mean attaching values with their respective columns. You need to do something like ...