添加1,383字节
、 2020年10月16日 (五) 17:55
[[File:cloud_large.png|600px]]
安装包需求:
首先要安装PDFMiner以把一个PDF文件转成txt文件。在[https://pypi.python.org/pypi/pdfminer/ 这里]下载,在[http://www.unixuser.org/~euske/python/pdfminer/index.html#todo 这里]是文件使用说明。
其次要安装[http://www.pygame.org/download.shtml Pygame](windows下要用msi安装包安装,用easy_install有可能出错)。
接着安装simplejson,使用easy_install即可。
最后,easy_install安装[https://pypi.python.org/pypi/pytagcloud pytagcloud]即可。
<syntaxhighlight lang="python">
from pytagcloud import create_tag_image, make_tags
from pytagcloud.lang.counter import get_tag_counts
from collections import Counter
import random
f = open("E:\wulingfei\data_science_and_prediction.txt","r").read()
s=f.split("\n")
tt=[i.strip(" ") for i in s if len(i)>40]
text=[]
for j in tt:
j = j.split(" ")
for i in j:
if len(i)>5:
text.append(i)
ct=Counter(text)
nct={key:ct[key] for key in ct if ct[key]>4}
nt=" ".join([i for i in text if i in nct])
tags = make_tags(get_tag_counts(nt), maxsize=100)
create_tag_image(tags, 'E:\wulingfei\cloud_large.png', size=(900, 600), fontname='Lobster')
</syntaxhighlight>
[[category:python]]
[[category:旧词条迁移]]