首页 > 编程语言 > 详细

第一个python学习笔记

时间:2018-02-01 22:40:54      阅读:299      评论:0      收藏:0      [点我收藏+]
年纪大了跟不上啊,哈哈
# !/usr/env pythen
# -*- coding:utf-8 -*-
"""
分析
import string

"""
# 文件操作 读、写、二进制
# fb=open(‘emma.txt‘,‘r‘)
# content=fb.read()
# bp.close()
with open(‘emma.txt‘,‘r‘)as fb
content = fb.read()
# print(content)
# res=‘a b c‘.split()
# 清洗数据,把标点符号去掉
content=content.replace(‘-‘,‘‘)
word_list=content.split()
for i in string.punctuation:
content=content.replace(i,‘‘)
# 得到了单词的列表
# print(string.punctuation)
# print(word_list[:100])
# content.split()
word_list=content.split()
# 统计每个单词的频率
data={}
for word in word_list
word=word.lower() # 规范格式为小写
if word in data:
data[word]+=1
else:
data[word]=1
#data[word] = data.get(word,0)+1
hist=[]
# 排序
for key,vars in data.items()
this.append([value,key])

hist.sort(reverse=true)
print(hist) # 倒序

# 画图 matplotlib
#print(hist)
for item in hist[:10]
plt.bara((item[1]),(item[0]))
plt.legend()
plt.xlabel(‘word‘)
plt.ylabel(‘rate‘)
plt.title(‘‘)
plt.show

第一个python学习笔记

原文:https://www.cnblogs.com/ziqiangcn/p/8401490.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!