0

我想计算我的数据实体的结果。

这是我的df:

my_dict = {"customer_1": "Adidas é melhor do que Nike", "customer_2": "Até que Nike é bom", "customer_3": "Eu gosto do Google e da Microsoft"}

my_df = pd.DataFrame(list(my_dict.items()), columns = ['customer_id', 'review'])

print(my_df)

    customer_id   review
0   customer_1    Adidas é melhor do que Nike e Microsoft
1   customer_2    Até que Nike é bom
2   customer_3    Eu gosto do Google e da Microsoft

我正在使用 Polyglot 的文本来识别这样的实体:

# Create a new text object using Polyglot's Text class: txt
import polyglot
from polyglot.text import Text, Word

txt = Text(my_df['review'][2])

# Print each of the entities found
for ent in txt.entities:
    print(ent)

['Google']
['Microsoft']

我不想在括号内输入行号(如上),而是希望得到这样的结果:

Entity    Count
Nike      2
Adidas    1
Google    1
Microsoft 2

到目前为止,我尝试了这个,但是没有用:

for i in x_col['Texto_Abertura']:
    txt = Text(x_col['Texto_Abertura'][i])

# Print each of the entities found
    for ent in txt.entities:
        counter += ent
4

0 回答 0