Python-新时代的智慧工具(二)

Python约=武侠小说中的功夫,功夫分门别类,Anaconda类似于功夫中的“独孤九剑”。

庞大的可扩展的第三方平台+可破各种难题的库+灵活自由的Jupyter...


用Jupyter先简单实现一个文字意思分析。

以川普的就职演讲为例:http://edition.cnn.com/2017/01/20/politics/trump-inaugural-address/

第一步,导入要分析的文章:

speech_text = '''这里是要分析的文章'''

speech = speech_text.lower().split() 

第二步,导入字典

dic = {}

for word in speech:

    if word not in dic:

          dic[word] = 1

      else:

            dic[word] = dic[word] + 1

dic.items()

第三步:分析所有单词出现的频率

import operator

swd = sorted(dic.items(), key = operator.itemgetter(1), reverse=True)

swd

一大推介词...

第四步:拿掉介词

from nltk.corpus import stopwords

stop_words = stopwords.words('English')

#stop_words

for k,v in swd:

      if k not in stop_words:

            print(k,v)

成了,看看川普口中的词,果然口口声声“爱国”啊...

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容