html - 在数据框中唯一地计算单词
问题描述
for filename in glob.glob(os.path.join(folder_path, '*.html')):
with open(filename, 'r',encoding='utf-8') as f:
text = f.read()
print (filename)
#print (text)
patent = BeautifulSoup(text)
cleantext = patent.get_text()
clean_lower=cleantext.lower()
for char in clean_lower:
>> if char not in punctuations:
no_punct = no_punct + char
for word in dictionary:
>>if word in no_punct:
>>>wordlist.append(word)
>>>countlist.append(no_punct.count(word))
print(wordlist,countlist)
df = pd.DataFrame({'word':wordlist, 'count':countlist})
df.columns=['word','count']
df=df.set_index('word')
print(df)
['steam', 'heating', 'horizontal well', 'electromagnetic', 'single well', 'steam', 'foam', 'heating', 'horizontal well', 'solvent', 'hexane', 'electromagnetic', 'steam foam', 'surfactant', 'single well', 'miscible'] [84, 9, 4, 2, 1, 89, 2, 10, 4, 5, 7, 2, 1, 106, 1, 1]
count
word
steam 84
heating 9
horizontal well 4
electromagnetic 2
single well 1
steam 89
foam 2
heating 10
horizontal well 4
solvent 5
hexane 7
electromagnetic 2
steam foam 1
surfactant 106
single well 1
miscible 1
我没有得到唯一的输出,有人能告诉我我在哪里犯了错误吗?字蒸汽的数量应该是 89,但我希望它只打印一次。
解决方案
count
word
steam 84
heating 9
horizontal well 4
electromagnetic 2
single well 1
steam 5
foam 2
heating 1
solvent 5
hexane 7
steam foam 1
surfactant 106
miscible 1
```
How can I add the count of words like example steam=84+5=89 from this data frame. How can I have the code uniquely count the word and add the number of occurences to one word.
推荐阅读
- c# - 如何让 C# 2017 IntelliSense 像 2008 一样工作?
- docker - 添加外网使MySQL数据库无法访问
- angular - 从 Angular5 升级到 Angular7 后,切片管道进入无限循环
- java - 使用嵌套循环打印数字
- c# - 在 Unity 中为没有动画师的多个精灵制作动画
- python - 如何修复质数检查/分解功能
- post - 如何在 Postman 中调用请求
- scala - 如何将 Ordering 显式传递给隐式扩充
- spring-boot - 不要为匿名用户启动会话
- python - ValueError:在使用这种多对多关系之前需要字段“id”的值