Python Forum
From string parameter to a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
From string parameter to a dictionary
#1
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



Reply


Messages In This Thread
From string parameter to a dictionary - by Mitchie87 - Oct-11-2019, 03:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  to find in dictionary given parameter 'name' and to output position Liki 10 1,341 Oct-08-2023, 06:38 AM
Last Post: Pedroski55
  How to change part of the value string in Python Dictionary? sbabu 11 3,906 Feb-12-2020, 02:25 AM
Last Post: sbabu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020