Datasets:
Upload reddit_climate_comment.py
Browse files- reddit_climate_comment.py +19 -9
reddit_climate_comment.py
CHANGED
|
@@ -74,26 +74,35 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 74 |
|
| 75 |
comments = []
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
if pd.isna(comment_id): # Skip if CommentID is NaN
|
| 81 |
continue
|
| 82 |
|
| 83 |
comment = {
|
| 84 |
"CommentID": comment_id,
|
| 85 |
-
"CommentAuthor":
|
| 86 |
-
"CommentBody":
|
| 87 |
-
"CommentTimestamp":
|
| 88 |
-
"CommentUpvotes":
|
| 89 |
-
"CommentPermalink":
|
| 90 |
"replies": [] # Initialize empty list for replies
|
| 91 |
}
|
| 92 |
|
| 93 |
# Check if 'replies' column exists and is not NaN
|
| 94 |
-
if
|
| 95 |
# Filter out NaNs from reply IDs
|
| 96 |
-
reply_ids = [str(reply_id) for reply_id in
|
| 97 |
|
| 98 |
# Add replies for the current comment
|
| 99 |
for reply_id in reply_ids:
|
|
@@ -127,5 +136,6 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 127 |
|
| 128 |
|
| 129 |
|
|
|
|
| 130 |
|
| 131 |
|
|
|
|
| 74 |
|
| 75 |
comments = []
|
| 76 |
|
| 77 |
+
# Extract comment data
|
| 78 |
+
comment_ids = group['CommentID'].tolist()
|
| 79 |
+
comment_authors = group['CommentAuthor'].tolist()
|
| 80 |
+
comment_bodies = group['CommentBody'].tolist()
|
| 81 |
+
comment_timestamps = group['CommentTimestamp'].tolist()
|
| 82 |
+
comment_upvotes = group['CommentUpvotes'].tolist()
|
| 83 |
+
comment_permalinks = group['CommentPermalink'].tolist()
|
| 84 |
+
replies = group['replies'].tolist() # Assuming 'replies' column is a list
|
| 85 |
+
|
| 86 |
+
for i in range(len(comment_ids)):
|
| 87 |
+
comment_id = str(comment_ids[i])
|
| 88 |
|
| 89 |
if pd.isna(comment_id): # Skip if CommentID is NaN
|
| 90 |
continue
|
| 91 |
|
| 92 |
comment = {
|
| 93 |
"CommentID": comment_id,
|
| 94 |
+
"CommentAuthor": comment_authors[i],
|
| 95 |
+
"CommentBody": comment_bodies[i],
|
| 96 |
+
"CommentTimestamp": comment_timestamps[i],
|
| 97 |
+
"CommentUpvotes": comment_upvotes[i],
|
| 98 |
+
"CommentPermalink": comment_permalinks[i],
|
| 99 |
"replies": [] # Initialize empty list for replies
|
| 100 |
}
|
| 101 |
|
| 102 |
# Check if 'replies' column exists and is not NaN
|
| 103 |
+
if replies[i] is not None and not pd.isna(replies[i]):
|
| 104 |
# Filter out NaNs from reply IDs
|
| 105 |
+
reply_ids = [str(reply_id) for reply_id in replies[i] if not pd.isna(reply_id)]
|
| 106 |
|
| 107 |
# Add replies for the current comment
|
| 108 |
for reply_id in reply_ids:
|
|
|
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
+
|
| 140 |
|
| 141 |
|