Datasets:
Upload reddit_climate_comment.py
Browse files- reddit_climate_comment.py +16 -9
reddit_climate_comment.py
CHANGED
|
@@ -77,8 +77,11 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 77 |
for index, comment_row in group.iterrows():
|
| 78 |
comment_id = str(comment_row['CommentID'])
|
| 79 |
|
|
|
|
|
|
|
|
|
|
| 80 |
comment = {
|
| 81 |
-
"
|
| 82 |
"CommentAuthor": comment_row['CommentAuthor'],
|
| 83 |
"CommentBody": comment_row['CommentBody'],
|
| 84 |
"CommentTimestamp": comment_row['CommentTimestamp'],
|
|
@@ -87,16 +90,19 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 87 |
"replies": []
|
| 88 |
}
|
| 89 |
|
|
|
|
|
|
|
|
|
|
| 90 |
# Add replies for the current comment
|
| 91 |
-
|
| 92 |
-
|
| 93 |
reply = {
|
| 94 |
-
"ReplyID":
|
| 95 |
-
"ReplyAuthor":
|
| 96 |
-
"ReplyBody":
|
| 97 |
-
"ReplyTimestamp":
|
| 98 |
-
"ReplyUpvotes":
|
| 99 |
-
"ReplyPermalink":
|
| 100 |
}
|
| 101 |
comment["replies"].append(reply)
|
| 102 |
|
|
@@ -117,5 +123,6 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 117 |
}
|
| 118 |
|
| 119 |
|
|
|
|
| 120 |
|
| 121 |
|
|
|
|
| 77 |
for index, comment_row in group.iterrows():
|
| 78 |
comment_id = str(comment_row['CommentID'])
|
| 79 |
|
| 80 |
+
if pd.isna(comment_id): # Skip if CommentID is NaN
|
| 81 |
+
continue
|
| 82 |
+
|
| 83 |
comment = {
|
| 84 |
+
"CommentID": comment_id,
|
| 85 |
"CommentAuthor": comment_row['CommentAuthor'],
|
| 86 |
"CommentBody": comment_row['CommentBody'],
|
| 87 |
"CommentTimestamp": comment_row['CommentTimestamp'],
|
|
|
|
| 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 |
|
|
|
|
| 123 |
}
|
| 124 |
|
| 125 |
|
| 126 |
+
|
| 127 |
|
| 128 |
|