-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare_texts.py
More file actions
40 lines (36 loc) · 1.45 KB
/
prepare_texts.py
File metadata and controls
40 lines (36 loc) · 1.45 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pandas as pd
def preparar_textos_nodos(df):
textos = []
for _, row in df.iterrows():
usuario = row.get("usuario", "usuario desconocido")
texto = row.get("texto", "")
followers = row.get("followers_count", 0)
following = row.get("following_count", 0)
num_tweets = row.get("num_tweets", 0)
sentiment = row.get("sentiment", "neutral")
is_bot = row.get("is_bot", False)
descripcion = (
f"El usuario {usuario} publicó: '{texto}'. "
f"Tiene {followers} seguidores, sigue a {following} cuentas "
f"y ha publicado {num_tweets} tuits. "
f"Su sentimiento promedio es {sentiment} "
f"y {'parece un bot' if is_bot else 'parece una persona real'}."
)
textos.append(descripcion)
df["texto_completo"] = textos
return df
def preparar_textos_edges(df):
textos = []
for _, row in df.iterrows():
origen = row.get("origen", "desconocido")
destino = row.get("destino", "desconocido")
tipo = row.get("tipo_interaccion", "interaccion")
peso = row.get("peso", 0)
edge_sentiment = row.get("edge_sentiment", 0)
descripcion = (
f"El usuario {origen} tuvo una interacción tipo {tipo} con {destino}, "
f"con un peso de {peso} y un sentimiento de {edge_sentiment:.2f}."
)
textos.append(descripcion)
df["texto_completo"] = textos
return df