1
I have a code where I will have a function that will pass the data from a csv file to a dictionary. The process will be to take the films with their respective notes and add to a dictionary relative to each user, and to add these dictionaries to a main dictionary.
import csv
path = 'C:\\Users\\Rafael\\Desktop\\DataMining\\RECOMMENDATION\\Movie_Ratings.csv'
data = {}
def loadCSV():
file = open(path, newline='')
reader = csv.reader(file)
header = next(reader)
header.remove('')
n = 0
for u in header:
n += 1
data[u] = {}
for line in reader:
data[u][line[0]] = line[n]
loadCSV()
print(data)
However, when running my code...
{'Patrick C': {'Alien': '', 'Avatar': '4', 'Blade Runner': '5', 'Braveheart': '4', 'Dodgeball': '5', 'Forest Gump': '4', 'Gladiator': '', 'Jaws': '', 'Kazaam': '2', 'Lord of the Rings': '4', 'Napolean Dynamite': '3', 'Old School': '3', 'Pootie Tang': '', 'Pulp Fiction': '', 'Scarface': '', 'Shawshank Redemption': '5', 'Snakes on a Plane': '4', 'Spiderman': '4', 'Star Wars': '5', 'The Dark Knight': '4', 'The Happening': '1', 'The Matrix': '3', 'Toy Story': '4', 'Village': '', 'You Got Mail': '1'}, 'Heather': {}, 'Bryan': {}, 'Patrick T': {}, 'Thomas': {}, 'aaron': {}, 'vanessa': {}, 'greg': {}, 'brian': {}, 'ben': {}, 'Katherine': {}, 'Jonathan': {}, 'Zwe': {}, 'Erin': {}, 'Chris': {}, 'Zak': {}, 'Matt': {}, 'Josh': {}, 'Amy': {}, 'Valerie': {}, 'Gary': {}, 'Stephen': {}, 'Jessica': {}, 'Jeff': {}}
...Only the first user receives the movie notes. Please HELP!!
Matheus, edit your question and put an example of how the file structure is Movie_ratings.csv
– NoobSaibot