ChenglongMa commited on
Commit
7fc9f2a
·
verified ·
1 Parent(s): b86d76f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +24 -0
README.md CHANGED
@@ -67,6 +67,30 @@ amazon-2023-all-category-k-core/
67
  3. Filter out the `meta` data and `reviews` of items that are not in the filtered `ratings`.
68
  4. Save the datasets in `.parquet` format.
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  ## Dataset Sources
71
 
72
  The original dataset is available at [Amazon reviews dataset](https://amazon-reviews-2023.github.io/).
 
67
  3. Filter out the `meta` data and `reviews` of items that are not in the filtered `ratings`.
68
  4. Save the datasets in `.parquet` format.
69
 
70
+ ### Core Code Snippets
71
+
72
+ ```python
73
+ # Iteratively remove all users and items with fewer than k ratings
74
+
75
+ k = 20
76
+
77
+ while True:
78
+ user_counts = df['user_id'].value_counts()
79
+ item_counts = df['parent_asin'].value_counts()
80
+
81
+ filtered_df = df[
82
+ df['user_id'].isin(user_counts[user_counts >= k].index) &
83
+ df['parent_asin'].isin(item_counts[item_counts >= k].index)
84
+ ]
85
+
86
+ if len(filtered_df) == len(df):
87
+ break
88
+
89
+ df = filtered_df
90
+
91
+ # `df` or `filtered_df` would be the resulted data.
92
+ ```
93
+
94
  ## Dataset Sources
95
 
96
  The original dataset is available at [Amazon reviews dataset](https://amazon-reviews-2023.github.io/).