我有一个问题,我想计算数据帧中的唯一单词,但不幸的是,它只计算第一句话.
text
0 hello is a unique sentences
1 hello this is a test
2 does this works
import pandas as pd
d = {
"text": ["hello is a unique sentences",
"hello this is a test",
"does this works"],
}
df = pd.DataFrame(data=d)
from collections import Counter
# Count unique words
def counter_word(text_col):
print(len(text_col.values))
count = Counter()
for i, text in enumerate(text_col.values):
print(i)
for word in text.split():
count[word] += 1
return count
counter = counter_word(df['text'])
len(counter)