ruanchaves commited on
Commit
30a0c9e
1 Parent(s): 6bbffc9
Files changed (1) hide show
  1. b2w-reviews01.py +17 -3
b2w-reviews01.py CHANGED
@@ -42,7 +42,7 @@ class Reviews(datasets.GeneratorBasedBuilder):
42
  description=_DESCRIPTION,
43
  features=datasets.Features(
44
  dict(
45
- submission_date=datasets.Value("string"),
46
  reviewer_id=datasets.Value("string"),
47
  product_id=datasets.Value("string"),
48
  product_name=datasets.Value("string"),
@@ -50,8 +50,8 @@ class Reviews(datasets.GeneratorBasedBuilder):
50
  site_category_lv1=datasets.Value("string"),
51
  site_category_lv2=datasets.Value("string"),
52
  review_title=datasets.Value("string"),
53
- overall_rating=datasets.Value("string"),
54
- recommend_to_a_friend=datasets.Value("string"),
55
  review_text=datasets.Value("string"),
56
  reviewer_birth_year=datasets.Value("int32"),
57
  reviewer_gender=datasets.Value("string"),
@@ -74,10 +74,24 @@ class Reviews(datasets.GeneratorBasedBuilder):
74
 
75
  def _generate_examples(self, filepath):
76
  def process_row(row):
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  try:
78
  row["reviewer_birth_year"] = int(float(row["reviewer_birth_year"]))
79
  except ValueError:
80
  row["reviewer_birth_year"] = None
 
81
  return row
82
  records = pd.read_csv(filepath).to_dict("records")
83
  for idx, row in enumerate(records):
 
42
  description=_DESCRIPTION,
43
  features=datasets.Features(
44
  dict(
45
+ submission_date=datasets.Value("timestamp[(s)]"),
46
  reviewer_id=datasets.Value("string"),
47
  product_id=datasets.Value("string"),
48
  product_name=datasets.Value("string"),
 
50
  site_category_lv1=datasets.Value("string"),
51
  site_category_lv2=datasets.Value("string"),
52
  review_title=datasets.Value("string"),
53
+ overall_rating=datasets.Value("int32"),
54
+ recommend_to_a_friend=datasets.Value("bool"),
55
  review_text=datasets.Value("string"),
56
  reviewer_birth_year=datasets.Value("int32"),
57
  reviewer_gender=datasets.Value("string"),
 
74
 
75
  def _generate_examples(self, filepath):
76
  def process_row(row):
77
+
78
+ recommend_key = {
79
+ "Yes": True,
80
+ "No": False,
81
+ "nan": None
82
+ }
83
+
84
+ row["recommend_to_a_friend"] = recommend_key[row["recommend_to_a_friend"]]
85
+
86
+ to_int_list = ["overall_rating", "product_id"]
87
+ for row_value in to_int_list:
88
+ row[row_value] = int(row[row_value])
89
+
90
  try:
91
  row["reviewer_birth_year"] = int(float(row["reviewer_birth_year"]))
92
  except ValueError:
93
  row["reviewer_birth_year"] = None
94
+
95
  return row
96
  records = pd.read_csv(filepath).to_dict("records")
97
  for idx, row in enumerate(records):