Spaces:
Runtime error
Runtime error
Upload agrega_sentimientos.py
Browse files- agrega_sentimientos.py +27 -0
agrega_sentimientos.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from pysentimiento import create_analyzer
|
3 |
+
def genera_excel_sentimientos(noticias):
|
4 |
+
titulos_buscados=noticias.titulo
|
5 |
+
from pysentimiento import create_analyzer
|
6 |
+
analyzer = create_analyzer(task="sentiment", lang="es")
|
7 |
+
sentimientos=[]
|
8 |
+
negativos=[]
|
9 |
+
neutros=[]
|
10 |
+
positivos=[]
|
11 |
+
for titulo in titulos_buscados:
|
12 |
+
prediccion=analyzer.predict(titulo)
|
13 |
+
sentimientos.append(prediccion.output)
|
14 |
+
negativos.append(prediccion.probas['NEG'])
|
15 |
+
neutros.append(prediccion.probas['NEU'])
|
16 |
+
positivos.append(prediccion.probas['POS'])
|
17 |
+
print(prediccion)
|
18 |
+
|
19 |
+
noticias=noticias.copy()
|
20 |
+
noticias['sentimiento']=sentimientos
|
21 |
+
noticias['pond_negativos']=negativos
|
22 |
+
noticias['pond_neutro']=neutros
|
23 |
+
noticias['pond_positivo']=positivos
|
24 |
+
|
25 |
+
#noticias.to_excel("noticias_con_sentimientos.xlsx")
|
26 |
+
|
27 |
+
return noticias
|