cathw commited on
Commit
d7db531
·
verified ·
1 Parent(s): cdeafd7

Upload reddit_climate_comment.py

Browse files
Files changed (1) hide show
  1. reddit_climate_comment.py +14 -1
reddit_climate_comment.py CHANGED
@@ -55,6 +55,8 @@ class NewDataset(GeneratorBasedBuilder):
55
 
56
  def _generate_examples(self, filepath):
57
  df = pd.read_csv(filepath)
 
 
58
  grouped_df = df.groupby('PostID')
59
 
60
  for post_id, group in grouped_df:
@@ -71,9 +73,19 @@ class NewDataset(GeneratorBasedBuilder):
71
  post_permalink = post_data['PostPermalink']
72
 
73
  comments = []
 
 
74
  for index, comment_row in group.iterrows():
 
 
 
 
 
 
 
 
75
  comment = {
76
- "CommentID": str(comment_row['CommentID']),
77
  "CommentAuthor": comment_row['CommentAuthor'],
78
  "CommentBody": comment_row['CommentBody'],
79
  "CommentTimestamp": comment_row['CommentTimestamp'],
@@ -110,5 +122,6 @@ class NewDataset(GeneratorBasedBuilder):
110
  "post_permalink": post_permalink,
111
  "comments": comments
112
  }
 
113
 
114
 
 
55
 
56
  def _generate_examples(self, filepath):
57
  df = pd.read_csv(filepath)
58
+
59
+ # Group the DataFrame by post ID
60
  grouped_df = df.groupby('PostID')
61
 
62
  for post_id, group in grouped_df:
 
73
  post_permalink = post_data['PostPermalink']
74
 
75
  comments = []
76
+ seen_comment_ids = set() # Set to keep track of seen comment IDs
77
+
78
  for index, comment_row in group.iterrows():
79
+ comment_id = str(comment_row['CommentID'])
80
+
81
+ # Check if comment ID has been seen before
82
+ if comment_id in seen_comment_ids:
83
+ continue # Skip duplicate comments
84
+ else:
85
+ seen_comment_ids.add(comment_id)
86
+
87
  comment = {
88
+ "CommentID": comment_id,
89
  "CommentAuthor": comment_row['CommentAuthor'],
90
  "CommentBody": comment_row['CommentBody'],
91
  "CommentTimestamp": comment_row['CommentTimestamp'],
 
122
  "post_permalink": post_permalink,
123
  "comments": comments
124
  }
125
+
126
 
127