cathw commited on
Commit
85af435
·
verified ·
1 Parent(s): 0776676

Upload reddit_climate_comment.py

Browse files
Files changed (1) hide show
  1. reddit_climate_comment.py +19 -16
reddit_climate_comment.py CHANGED
@@ -87,24 +87,26 @@ class NewDataset(GeneratorBasedBuilder):
87
  "CommentTimestamp": comment_row['CommentTimestamp'],
88
  "CommentUpvotes": comment_row['CommentUpvotes'],
89
  "CommentPermalink": comment_row['CommentPermalink'],
90
- "replies": []
91
  }
92
 
93
- # Filter out NaNs from reply IDs
94
- reply_ids = [str(reply_id) for reply_id in comment_row['replies'] if not pd.isna(reply_id)]
95
-
96
- # Add replies for the current comment
97
- for reply_id in reply_ids:
98
- reply_data = group[group['ReplyID'] == reply_id].iloc[0]
99
- reply = {
100
- "ReplyID": reply_id,
101
- "ReplyAuthor": reply_data['ReplyAuthor'],
102
- "ReplyBody": reply_data['ReplyBody'],
103
- "ReplyTimestamp": reply_data['ReplyTimestamp'],
104
- "ReplyUpvotes": reply_data['ReplyUpvotes'],
105
- "ReplyPermalink": reply_data['ReplyPermalink']
106
- }
107
- comment["replies"].append(reply)
 
 
108
 
109
  comments.append(comment)
110
 
@@ -124,5 +126,6 @@ class NewDataset(GeneratorBasedBuilder):
124
 
125
 
126
 
 
127
 
128
 
 
87
  "CommentTimestamp": comment_row['CommentTimestamp'],
88
  "CommentUpvotes": comment_row['CommentUpvotes'],
89
  "CommentPermalink": comment_row['CommentPermalink'],
90
+ "replies": [] # Initialize empty list for replies
91
  }
92
 
93
+ # Check if 'replies' column exists and is not NaN
94
+ if 'replies' in comment_row.index and not pd.isna(comment_row['replies']):
95
+ # Filter out NaNs from reply IDs
96
+ reply_ids = [str(reply_id) for reply_id in comment_row['replies'] if not pd.isna(reply_id)]
97
+
98
+ # Add replies for the current comment
99
+ for reply_id in reply_ids:
100
+ reply_data = group[group['ReplyID'] == reply_id].iloc[0]
101
+ reply = {
102
+ "ReplyID": reply_id,
103
+ "ReplyAuthor": reply_data['ReplyAuthor'],
104
+ "ReplyBody": reply_data['ReplyBody'],
105
+ "ReplyTimestamp": reply_data['ReplyTimestamp'],
106
+ "ReplyUpvotes": reply_data['ReplyUpvotes'],
107
+ "ReplyPermalink": reply_data['ReplyPermalink']
108
+ }
109
+ comment["replies"].append(reply)
110
 
111
  comments.append(comment)
112
 
 
126
 
127
 
128
 
129
+
130
 
131