import os
import re
import sys
sys.stdout=open('f1.txt','w')
from collections import Counter
from glob import glob
def removegarbage(text):
text=re.sub(r'\W+',' ',text)
text=text.lower()
return text
folderpath='d:/induvidual-articles'
counter=Counter()
filepaths = glob(os.path.join(folderpath,'*.txt'))
num_files = len(filepaths)
with open('topics.txt','r') as filehandle:
lines = filehandle.read()
words = removegarbage(lines).split()
counter.update(words)
for word, count in counter.most_common():
probability=count//num_files
print('{} {} {}'.format(word,count,probability))
는
내가 제로 나누기 오류가 점점 오전 : 라인 확률 제로 에 의해 플로트 부문 = // NUM_FILES 파이썬에서 제로 나누기 오류를 해결하는 방법은 무엇입니까?
내가 어떻게 그것을 수습 할
계산?난의 형식으로 내 출력을 필요 단어, 계산, 확률
Plz은 도움을!
그래서'num_files'는 0입니다. 정확한 파일 경로를 얻었습니까? –
"유도 형"- 정말요? – RichieHindle
예! 여기에서 카운트 값은 1-10 범위에 있고 num_files는 20,000 범위에 있습니다. –