-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
25 lines (20 loc) · 749 Bytes
/
process.py
File metadata and controls
25 lines (20 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import nltk
import pandas as pd
nltk.download('punkt')
from textblob import TextBlob
def do_nothing(word):
return word
def get_file_polarity():
comments = pd.read_csv("dummy_comments.csv").drop(columns='createdAt').head(5)
# for each row, run textblob on the column body and write the result in a new column called "polarity"
comments['polarity'] = comments.body.apply(
lambda x: TextBlob(x).sentiment.polarity)
return comments.to_json()
def get_comment_polarity(comment):
return {
"COMMENT": comment,
"POLARITY": TextBlob(comment).sentiment.polarity
}
def get_many_comments_polarity(comment_list):
# return [get_comment_polarity(comment) for comment in comment_list]
return [comment for comment in comment_list]