Datasets:
Upload reddit_climate_comment.py
Browse files- reddit_climate_comment.py +47 -46
reddit_climate_comment.py
CHANGED
|
@@ -55,54 +55,55 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 55 |
|
| 56 |
def _generate_examples(self, filepath):
|
| 57 |
df = pd.read_csv(filepath)
|
| 58 |
-
# Replace pd.NA with None for all columns
|
| 59 |
-
for column in df.columns:
|
| 60 |
-
df[column] = df[column].replace({pd.NA: None})
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
}
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
"
|
| 85 |
-
"
|
| 86 |
-
"
|
| 87 |
-
"
|
| 88 |
-
"
|
| 89 |
-
"
|
| 90 |
-
"replies": []
|
| 91 |
}
|
| 92 |
-
reply
|
| 93 |
-
reply_id = row["ReplyID"]
|
| 94 |
-
if reply_id:
|
| 95 |
-
for j in range(0,len(reply_id)):
|
| 96 |
-
reply_data = {"ReplyID": reply_id[j],
|
| 97 |
-
"ReplyAuthor": row["ReplyAuthor"][j],
|
| 98 |
-
"ReplyBody": row["ReplyBody"][j],
|
| 99 |
-
"ReplyTimestamp": row["ReplyTimestamp"][j],
|
| 100 |
-
"ReplyUpvotes": int(row["ReplyUpvotes"][j]),
|
| 101 |
-
"ReplyPermalink": row["ReplyPermalink"][j]
|
| 102 |
-
}
|
| 103 |
-
comment_data["replies"].append(reply_data)
|
| 104 |
-
post_data["comments"].append(comment_data)
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
|
|
|
| 55 |
|
| 56 |
def _generate_examples(self, filepath):
|
| 57 |
df = pd.read_csv(filepath)
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
for index, row in df.iterrows():
|
| 60 |
+
post_id = str(row['PostID'])
|
| 61 |
+
post_title = row['PostTitle']
|
| 62 |
+
post_author = row['PostAuthor']
|
| 63 |
+
post_body = row['PostBody']
|
| 64 |
+
post_url = row['PostUrl']
|
| 65 |
+
post_pic = row['PostPic']
|
| 66 |
+
subreddit = row['Subreddit']
|
| 67 |
+
post_timestamp = row['PostTimestamp']
|
| 68 |
+
post_upvotes = row['PostUpvotes']
|
| 69 |
+
post_permalink = row['PostPermalink']
|
| 70 |
+
|
| 71 |
+
comments = []
|
| 72 |
+
if not pd.isnull(row['CommentID']):
|
| 73 |
+
comment = {
|
| 74 |
+
"CommentID": str(row['CommentID']),
|
| 75 |
+
"CommentAuthor": row['CommentAuthor'],
|
| 76 |
+
"CommentBody": row['CommentBody'],
|
| 77 |
+
"CommentTimestamp": row['CommentTimestamp'],
|
| 78 |
+
"CommentUpvotes": row['CommentUpvotes'],
|
| 79 |
+
"CommentPermalink": row['CommentPermalink'],
|
| 80 |
+
"replies": []
|
| 81 |
}
|
| 82 |
+
comments.append(comment)
|
| 83 |
+
|
| 84 |
+
# If there are replies, add them to the comment
|
| 85 |
+
if not pd.isnull(row['ReplyID']):
|
| 86 |
+
reply = {
|
| 87 |
+
"ReplyID": str(row['ReplyID']),
|
| 88 |
+
"ReplyAuthor": row['ReplyAuthor'],
|
| 89 |
+
"ReplyBody": row['ReplyBody'],
|
| 90 |
+
"ReplyTimestamp": row['ReplyTimestamp'],
|
| 91 |
+
"ReplyUpvotes": row['ReplyUpvotes'],
|
| 92 |
+
"ReplyPermalink": row['ReplyPermalink']
|
|
|
|
| 93 |
}
|
| 94 |
+
comment["replies"].append(reply)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
yield post_id, {
|
| 97 |
+
"id": post_id,
|
| 98 |
+
"post_title": post_title,
|
| 99 |
+
"post_author": post_author,
|
| 100 |
+
"post_body": post_body,
|
| 101 |
+
"post_url": post_url,
|
| 102 |
+
"post_pic": post_pic,
|
| 103 |
+
"subreddit": subreddit,
|
| 104 |
+
"post_timestamp": post_timestamp,
|
| 105 |
+
"post_upvotes": post_upvotes,
|
| 106 |
+
"post_permalink": post_permalink,
|
| 107 |
+
"comments": comments
|
| 108 |
+
}
|
| 109 |
|