|
楼主 |
发表于 2021-5-19 18:57:04
|
显示全部楼层
- wordlist = ['你好','再见','你好','再见','你好','再见','你好','再见','你好','再见','欧了','拜拜','你好']
- wordset = set(wordlist) #去掉重复内容
- from openpyxl import Workbook #导入Excel模块 #导入时间模块
- wb = Workbook() #创建一个Excel文件
- sheet = wb.active #获取当前sheet名称
- print(sheet.title) #打印sheet名称标题 ,也可以print(wb.active.title)
- sheet.title = "第一个sheet" #修改sheet名称
- print(wb.active.title) #打印修改后的sheet标题
- sheet['A1']= "姓名" #在c4 d4单元格输入内容
- sheet['B1']= "次数"
- for word in wordset:
- freq = wordlist.count(word) #计算出现次数
- sheet.append([word,freq])
- wb.save( "测试10.xlsx") #保存到本级目录
复制代码
|
|