cathw commited on
Commit
eb06ee6
·
verified ·
1 Parent(s): a823de1

Upload reddit_climate_comment.py

Browse files
Files changed (1) hide show
  1. reddit_climate_comment.py +20 -32
reddit_climate_comment.py CHANGED
@@ -75,47 +75,34 @@ class NewDataset(GeneratorBasedBuilder):
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:
109
- reply_data = group[group['ReplyID'] == reply_id].iloc[0]
110
- reply = {
111
- "ReplyID": reply_id,
112
- "ReplyAuthor": reply_data['ReplyAuthor'],
113
- "ReplyBody": reply_data['ReplyBody'],
114
- "ReplyTimestamp": reply_data['ReplyTimestamp'],
115
- "ReplyUpvotes": reply_data['ReplyUpvotes'],
116
- "ReplyPermalink": reply_data['ReplyPermalink']
117
- }
118
- comment["replies"].append(reply)
119
 
120
  comments.append(comment)
121
 
@@ -137,5 +124,6 @@ class NewDataset(GeneratorBasedBuilder):
137
 
138
 
139
 
 
140
 
141
 
 
75
  comments = []
76
 
77
  # Extract comment data
78
+ for index, comment_row in group.iterrows():
79
+ comment_id = str(comment_row['CommentID'])
 
 
 
 
 
 
 
 
80
 
81
  if pd.isna(comment_id): # Skip if CommentID is NaN
82
  continue
83
 
84
  comment = {
85
  "CommentID": comment_id,
86
+ "CommentAuthor": comment_row['CommentAuthor'],
87
+ "CommentBody": comment_row['CommentBody'],
88
+ "CommentTimestamp": comment_row['CommentTimestamp'],
89
+ "CommentUpvotes": comment_row['CommentUpvotes'],
90
+ "CommentPermalink": comment_row['CommentPermalink'],
91
  "replies": [] # Initialize empty list for replies
92
  }
93
 
94
+ # Check if there are replies for the current comment
95
+ replies_data = group[group['CommentID'] == comment_id][['ReplyID', 'ReplyAuthor', 'ReplyBody', 'ReplyTimestamp', 'ReplyUpvotes', 'ReplyPermalink']]
96
+ for _, reply_data in replies_data.iterrows():
97
+ reply = {
98
+ "ReplyID": str(reply_data['ReplyID']),
99
+ "ReplyAuthor": reply_data['ReplyAuthor'],
100
+ "ReplyBody": reply_data['ReplyBody'],
101
+ "ReplyTimestamp": reply_data['ReplyTimestamp'],
102
+ "ReplyUpvotes": reply_data['ReplyUpvotes'],
103
+ "ReplyPermalink": reply_data['ReplyPermalink']
104
+ }
105
+ comment["replies"].append(reply)
 
 
 
 
 
106
 
107
  comments.append(comment)
108
 
 
124
 
125
 
126
 
127
+
128
 
129