python词频统计


词频统计预处理
下载一首英文的歌词或文章
将所有,.?!’:等分隔符全部替换为空格
将所有大写转换为小写
生成单词列表
生成词频统计
排序
排除语法型词汇,代词、冠词、连词
输出词频最大TOP10

s='Robert Zoellick, a former US Trade Representative and head of the World Bank, once said: "Trade was more about politics than economics." Indeed, international trade among nations is all about business, but once politicians step in, it becomes polarizing with unexpected consequences that could lead to a trade war.' \
'The ever-boastful US President Donald Trump tweeted that "trade wars are good, and easy to win". His newly appointed top economic advisor, Larry Kudlow, should remind him that trade wars are a pyrrhic form of competition in which even the victor is left worse off.' \
'The US Constitution clearly states: "Congress shall regulate interstate and foreign commerce." It grants authority to the executive branch to negotiate trade agreements, but it has the last word on increasing tariffs, whether it But Trump has no patience to follow such procedures. Instead he is issuing executive orders to satisfy his political base.' \
'The Republicans in Congress were shocked that their leader would take such a protectionist action, recognizing it was more about politics than national security. Their swift opposition forced Trump to make Canada and Mexico exceptions (to be part of North American Free Trade Agreement negotiations), and eventually minimize the effects on the US' \
'There will not be a trade war with these countries. If it occurs, it will be with China. The Trump administration has already taken shots that may spark a trade war, including slapping tariffs on solar panels. The next, and most fierce, battlefield in today''s smartphones to enter the US market. Around the corner is Section 301 of the Trade Act of 1974 — originally intended to safeguard patent rights — that will give the US president the authority to limit China'
s1=s.replace('?','')
s2=s1.replace(':','')
s3=s2.replace(',','')
s4=s3.replace('!','')
s5=s4.replace('','')
s6=s5.replace('"','')
s7=s6.replace('-','')
s8=s7.replace('.','')
s9=s8.lower()
list1=s9.split()
for i in list1:
print(i)
myset=set(list1)
print(myset)
key={}
for i in myset:
key[i]=list1.count(i)
print(key[i])
for i in {'a','an','the','to','in','on','is','are','too','am'}:
if i in key:
key.pop(i)
sort=sorted(key.items(),key=lambda d:d[1],reverse=True)
for j in range(10):
print(sort[j])

转载于:https://www.cnblogs.com/cairuiqi/p/8627772.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值