jamescalam commited on
Commit
e7a2c7b
1 Parent(s): 57f8196

Update movielens-recent-ratings.py

Browse files
Files changed (1) hide show
  1. movielens-recent-ratings.py +1 -15
movielens-recent-ratings.py CHANGED
@@ -33,7 +33,6 @@ class MovieLens(datasets.GeneratorBasedBuilder):
33
  "user_id": datasets.Value("int32"),
34
  "rating": datasets.Value("float32"),
35
  "title": datasets.Value("string"),
36
- "year": datasets.Value("int32"),
37
  }
38
  ),
39
  supervised_keys=None,
@@ -74,22 +73,9 @@ class MovieLens(datasets.GeneratorBasedBuilder):
74
  df["user_id"] = df["userId"].map(lambda x: mapping[x])
75
  # add "tt" prefix to align with IMDB URL IDs
76
  df["imdb_id"] = df["imdbId"].apply(lambda x: "tt" + str(x))
77
- # extract year from title where possible
78
- year_list = []
79
- find_year = re.compile(r"(?<=\()\d{4}(?=\))")
80
- for title in df['title']:
81
- match = find_year.search(title)
82
- if match:
83
- year_list.append(int(match[0]))
84
- else:
85
- year_list.append(None)
86
- # add year to df
87
- df['year'] = year_list
88
- # drop rows where no year is found
89
- df = df[~df["year"].isna()]
90
  # we also don't need all columns
91
  df = df[
92
- ["imdb_id", "movie_id", "user_id", "rating", "title", "year"]
93
  ]
94
  # save
95
  df.to_json(new_url+"/ratings.jsonl", orient="records", lines=True)
 
33
  "user_id": datasets.Value("int32"),
34
  "rating": datasets.Value("float32"),
35
  "title": datasets.Value("string"),
 
36
  }
37
  ),
38
  supervised_keys=None,
 
73
  df["user_id"] = df["userId"].map(lambda x: mapping[x])
74
  # add "tt" prefix to align with IMDB URL IDs
75
  df["imdb_id"] = df["imdbId"].apply(lambda x: "tt" + str(x))
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  # we also don't need all columns
77
  df = df[
78
+ ["imdb_id", "movie_id", "user_id", "rating", "title"]
79
  ]
80
  # save
81
  df.to_json(new_url+"/ratings.jsonl", orient="records", lines=True)