python对文本进行分词 对一段英文文本整理

PYTHON官方文档内置函数整理_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
PYTHON官方文档内置函数整理
阅读已结束,下载本文需要
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,同时保存到云知识,更方便管理
还剩3页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢博主最新文章
博主热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)python 读写txt文件 整理数据到另一个文件_百度知道
python 读写txt文件 整理数据到另一个文件
跪求大神,在线等。。。
例如:原数据文件test1.txt,数据如下
整理后数据文件text2.txt,数据如下
我有更好的答案
建议试试numpy 和pandas,好像有个tabulate之类的函数直接用。
我是菜鸟,刚学python没几天,想要代码,真心是不会写,心碎一地
为您推荐:
其他类似问题
您可能关注的内容
东风天龙的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。博主最新文章
博主热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)python统计文本文件内单词数量的方法
转载 & & 作者:不吃皮蛋
这篇文章主要介绍了python统计文本文件内单词数量的方法,涉及Python针对文本文件及字符串的相关操作技巧,需要的朋友可以参考下
本文实例讲述了python统计文本文件内单词数量的方法。分享给大家供大家参考。具体实现方法如下:
# count lines, sentences, and words of a text file
# set all the counters to zero
lines, blanklines, sentences, words = 0, 0, 0, 0
print '-' * 50
# use a text file you have, or google for this one ...
filename = 'GettysburgAddress.txt'
textf = open(filename, 'r')
except IOError:
print 'Cannot open file %s for reading' % filename
import sys
sys.exit(0)
# reads one line at a time
for line in textf:
print line,
lines += 1
if line.startswith('\n'):
blanklines += 1
# assume that each sentence ends with . or ! or ?
# so simply count these characters
sentences += line.count('.') + line.count('!') + line.count('?')
# create a list of words
# use None to split at any whitespace regardless of length
# so for instance double space counts as one space
tempwords = line.split(None)
print tempwords # test
# word total count
words += len(tempwords)
textf.close()
print '-' * 50
print "Lines
: ", lines
print "Blank lines: ", blanklines
print "Sentences : ", sentences
print "Words
: ", words
# optional console wait for keypress
from msvcrt import getch
希望本文所述对大家的python程序设计有所帮助。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

更多关于 python对文本进行分词 的文章

 

随机推荐