티스토리 뷰
728x90
반응형
파이썬 웹사이트 단어 빈도수 통계내기
파이썬으로 위키피디아 웹사이트 단어 빈도수 통계내기 이번에는 파이썬으로 간단한 프로젝트를 진행하며 ...
blog.naver.com
https://code.tutsplus.com/ko/tutorials/counting-word-frequency-in-a-file-using-python--cms-25965
파이썬을 이용해 파일에서 단어 빈도 계산하기
어떤 문서의 초점이 어디에 있는지 신속하게 파악하는 방법이 궁금했던 적은 없나요? 문서의 주요 주제는 무엇일까요? 제가 다음과 같은 간단한 요령을 한 가지 알려드리겠습니다. 문서에 언급
code.tutsplus.com
1.
from collections import Counter
import re
txt_path = '/Users/l.smin/PycharmProjects/pythonProject/img_object/detected_words.txt'
text = open(txt_path,'r')
text_str= text.read()
words = re.findall("\w+",text_str)
#print(words)
frequency = Counter(words).most_common()
#print(frequency)
frequency = dict(frequency)
print(frequency)
['bowl', 'bowl', 'bowl', 'dining', 'table', 'person', 'car', 'vase', 'potted', 'plant', 'bottle', 'bottle', 'bowl', 'bowl', 'bowl', 'cup', 'person', 'cup', 'person', 'dining', 'table', 'dog', 'person', 'car', 'person', 'truck', 'chair', 'dining', 'table', 'horse', 'dog', 'person', 'person', 'car', 'car', 'car', 'car', 'car', 'dining', 'table', 'person', 'person', 'car', 'car', 'truck', 'person', 'person', 'tie', 'bowl', 'sandwich', 'bowl', 'dining', 'table', 'bowl', 'tv', 'person', 'laptop', 'laptop', 'car', 'person', 'person', 'person', 'fire', 'hydrant', 'person', 'person', 'car', 'car', 'car', 'car', 'car', 'car', 'car', 'car', 'person', 'car', 'car', 'car', 'car', 'car', 'cat', 'cat', 'bowl', 'person', 'bowl', 'person', 'person', 'person', 'person', 'person', 'person', 'sandwich', 'broccoli', 'bowl', 'bowl', 'donut', 'dining', 'table', 'donut', 'person', 'chair', 'person', 'person', 'cat', 'airplane', 'wine', 'glass', 'cup', 'bowl', 'cup', 'dining', 'table', 'cup', 'pizza', 'bottle', 'person', 'person', 'frisbee', 'cup', 'bottle', 'person', 'banana', 'banana', 'banana', 'bottle', 'bottle', 'cup', 'person', 'person', 'person', 'person', 'person', 'person', 'bowl', 'dining', 'table', 'bowl', 'book', 'person', 'cat', 'vase', 'vase', 'vase', 'bed', 'person', 'bird', 'person', 'person', 'car', 'person', 'person', 'motorcycle', 'person', 'person', 'bicycle', 'bird', 'horse', 'cup', 'bottle', 'cat', 'horse', 'cow', 'person', 'suitcase', 'cake', 'bowl', 'bowl', 'dining', 'table', 'bowl', 'bowl']
[('person', 46), ('car', 24), ('bowl', 20), ('dining', 9), ('table', 9), ('cup', 8), ('bottle', 7), ('cat', 5), ('vase', 4), ('horse', 3), ('banana', 3), ('dog', 2), ('truck', 2), ('chair', 2), ('sandwich', 2), ('laptop', 2), ('donut', 2), ('bird', 2), ('potted', 1), ('plant', 1), ('tie', 1), ('tv', 1), ('fire', 1), ('hydrant', 1), ('broccoli', 1), ('airplane', 1), ('wine', 1), ('glass', 1), ('pizza', 1), ('frisbee', 1), ('book', 1), ('bed', 1), ('motorcycle', 1), ('bicycle', 1), ('cow', 1), ('suitcase', 1), ('cake', 1)]
{'person': 46, 'car': 24, 'bowl': 20, 'dining': 9, 'table': 9, 'cup': 8, 'bottle': 7, 'cat': 5, 'vase': 4, 'horse': 3, 'banana': 3, 'dog': 2, 'truck': 2, 'chair': 2, 'sandwich': 2, 'laptop': 2, 'donut': 2, 'bird': 2, 'potted': 1, 'plant': 1, 'tie': 1, 'tv': 1, 'fire': 1, 'hydrant': 1, 'broccoli': 1, 'airplane': 1, 'wine': 1, 'glass': 1, 'pizza': 1, 'frisbee': 1, 'book': 1, 'bed': 1, 'motorcycle': 1, 'bicycle': 1, 'cow': 1, 'suitcase': 1, 'cake': 1}
#save
total_txt_path = 'total.txt'
text_t = open(total_txt_path,'w+')
print(frequency, file=text_t)
728x90
반응형
'Coding > Python' 카테고리의 다른 글
python_ Touchdesigner : txt을 csv 파일로, 그래프로 표현하기 (0) | 2022.09.19 |
---|---|
python : 여러 사진 파일의 RGB 평균 구하기 (0) | 2022.09.10 |
python : 사진 분류 정리 (0) | 2022.06.22 |
Python_vi편집기 (0) | 2022.03.10 |
Python_자료형(문자열 슬라이싱) (0) | 2022.02.14 |
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- colab
- VR
- node.js
- motor controll
- TouchDesigner
- docker
- 유니티플러그인
- ardity
- sequelize
- DeepLeaning
- Python
- 유니티
- 라즈베리파이
- oculuspro
- unity 360
- Midjourney
- MQTT
- opencv
- CNC
- three.js
- houdini
- AI
- Express
- 후디니
- RNN
- Java
- imgtoimg
- Arduino
- emotive eeg
- Unity
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함
반응형