Adding in data with sentiment analysis

This commit is contained in:
Lucas Oskorep
2020-05-05 13:06:46 -05:00
parent 72ad18d95d
commit fca9d9efa2
9 changed files with 2699 additions and 14 deletions
+26
View File
@@ -0,0 +1,26 @@
from textblob import TextBlob
import pandas as pd
import preprocessor as p
from pathlib import Path
from glob import glob
def add_sent_analysis(file, dest):
df = pd.read_csv(file)
pol = []
subj = []
for index, row in df.iterrows():
tweet = row["tweet.text"]
tweet = p.clean(tweet)
tb = TextBlob(tweet)
pol.append(tb.polarity)
subj.append(tb.subjectivity)
df["pred_polarity"] = pol
df["pred_subj"] = subj
df.to_csv(dest, quoting=2, index=False)
for file in glob("./data/*"):
print(file)
print()
add_sent_analysis(file, "./processed_data/" + Path(file).name)
# default accuracy is 72% - NICE!