Skip to content

Instantly share code, notes, and snippets.

@yongjun823
Last active July 18, 2019 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yongjun823/0491efd597289ae8a1bf9e853014827c to your computer and use it in GitHub Desktop.
Save yongjun823/0491efd597289ae8a1bf9e853014827c to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import concurrent.futures
import os
import pandas as pd
import time
# from tqdm import tqdm_notebook as tqdm
from tqdm import tqdm
# import matplotlib.pyplot as plt
from textblob import TextBlob
def f(x):
polarity = TextBlob(x).polarity
return polarity
def main():
dir_name = 'val/'
jsons = os.listdir(dir_name)
df_arr = []
for val in tqdm(jsons):
df_t = pd.read_json(dir_name + val)
df_arr.append(df_t)
df = pd.concat(df_arr, ignore_index=True)
text_arr = list(df['text'])
sent_arr = []
with concurrent.futures.ProcessPoolExecutor() as executor:
for sent in executor.map(f, tqdm(text_arr)):
sent_arr.append(sent)
print(sum(sent_arr) / len(sent_arr))
if __name__ == '__main__':
s_time = time.time()
main()
print(f'end time {time.time() - s_time}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment