Oct-11-2019, 03:18 PM
Dear members, is there anybody would can help my with my homework question?
I'm able to open the csv file. But from there I really have no idea what to do.
The assignment:
Steven is working on his Master thesis and has some ratings combined in a file for his participants. Each line in this file contains a participant number, the lesson number and the rating separated by a semicolon (";") like:
participant_id;lesson_number;rating
103;4;2
103;5;1
He wants to run some analyses and wants to combine ratings of certain lessons in a dictionary. This dictionary should have the participant number as key and a list of ratings belonging to that participant as value. The index of the rating should be the same as the lesson, in other words, the first spot of the list is the rating of lesson 1, the second sport of the list is the rating of lesson 2 etc.
- You can assume that there are seven lessons in total.
- Participant number is an integer
- Rating is a float
Steven also has a lot of missing data, you should put an "NA" (not applicable) on each spot where he doesn't have a rating.
Write a function "ratings" which takes a string parameter "filename" as input. It must return a dictionary as described.
For example,
ratings("ratings.csv")returns
{'103': [2.0, 'NA', 'NA', 'NA', 'NA', 2.0 , 'NA']}
To test this function with this file, create a file named "ratings.csv" in the same directory as your solution and copy and paste the following text in the file:
participant_id;lesson_number;rating
103;1;2
103;6;2
I'm able to open the csv file. But from there I really have no idea what to do.
The assignment:
Steven is working on his Master thesis and has some ratings combined in a file for his participants. Each line in this file contains a participant number, the lesson number and the rating separated by a semicolon (";") like:
participant_id;lesson_number;rating
103;4;2
103;5;1
He wants to run some analyses and wants to combine ratings of certain lessons in a dictionary. This dictionary should have the participant number as key and a list of ratings belonging to that participant as value. The index of the rating should be the same as the lesson, in other words, the first spot of the list is the rating of lesson 1, the second sport of the list is the rating of lesson 2 etc.
- You can assume that there are seven lessons in total.
- Participant number is an integer
- Rating is a float
Steven also has a lot of missing data, you should put an "NA" (not applicable) on each spot where he doesn't have a rating.
Write a function "ratings" which takes a string parameter "filename" as input. It must return a dictionary as described.
For example,
ratings("ratings.csv")returns
{'103': [2.0, 'NA', 'NA', 'NA', 'NA', 2.0 , 'NA']}
To test this function with this file, create a file named "ratings.csv" in the same directory as your solution and copy and paste the following text in the file:
participant_id;lesson_number;rating
103;1;2
103;6;2