Datasets:
Upload reddit_climate_comment.py
Browse files- 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 |
-
#
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
| 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 |
|