语料 text = """My fellow citizens: I stand here today humbled by the task before us, grateful for the trust you've bestowed, mindful of the sacrifices borne by our ancestors. I thank President Bush for his service to our nation -- (applause)
python制作简单excel统计报表2之操作excel的模块openpyxl简单用法 # coding=utf-8 from openpyxl import Workbook, load_workbook from openpyxl.drawing.image import Image from openpyxl.styles import Font,colors from datetime import datetime import MySQLdb class ExcelUtils(obj
#瓦登尔湖词频统计: import string path = 'D:/python3/Walden.txt' with open(path,'r',encoding= 'utf-8') as text: words = [raw_word.strip(string.punctuation).lower() for raw_word in text.read().split()] words_index = set(words) counts_dict = {index:words.count(
现有列表如下: [6, 7, 5, 9, 4, 1, 8, 6, 2, 9] 希望统计各个元素出现的次数,可以看作一个词频统计的问题. 我们希望最终得到一个这样的结果:{6:2, 7:1...}即 {某个元素:出现的次数...} 首先要将这些元素作为字典的键,建立一个初值为空的字典: >>> from random import randint >>> l = [randint(1,10) for x in xrange(10)] >>> l [6,
# -*- coding: utf-8 -*- #!/usr/bin/env python import re f = open("C:\\Users\\陶敏\\Documents\\Pyscript\\test.txt") str = f.read() li = re.split(r'[, ;.\n\t]',str) for i in li: if(len(i))==0: li.remove(i) res_world = [] res_count = [] for i in li: