1 2 3 4 5 |
open ( '1.txt'
'r' ) as fp:
= fp.readlines()
= [line.split()[ 1 ][ 9
for
in lines]
open ( 'out.txt'
'w+' ) as out:
out.write( '\n' .join(res)) |
#encoding=utf-8
import jieba
import jieba.posseg as pseg
import re
filename='result.txt'
fileneedCut='test.txt'
fn=open(fileneedCut,"r")
f=open(filename,"w+")
for line in fn.readlines():
f.close()
fn.close()
- import
- sys.setdefaultencoding('utf-8'
- import
- import
- import#写入Excel表的库
- if"__main__"
- 'ascii'
- "wordCount")#Excel单元格名字
- forin'1.txt'):#1.txt是需要分词统计的文档
- '\n\r').split('\t'#制表格切分
- 0#jieba分词
- forin
- "wordCount.txt",'w'#打开文件
- forin
- ifnotin#统计数量
- 1
- else
- 1
- True
- forin
- forin
- if
- +str(word_dict[key])+'\n'#写入txt文档
- 0
- forin
- 1
- 0
- 'wordCount.xls'
1.txt是你需要分词统计的文本内容,最后会生成wordCount.txt和wordCount.xls两个文件。下图是最后结果