導航:首頁 > 編程語言 > python文本統計

python文本統計

發布時間:2022-09-07 04:08:49

『壹』 用python統計一段文本中單詞出現的次數

python有個特別簡單的方法就可以實現,直接用str的count方法就可以了,如下

『貳』 如何用python統計文本中重復行的數目

這個應該不難
先取出一行,存入字典key value=0
然後next 後面一行判斷是不是在字典的key里,如果在key里,value+1

完了就結束了,這了字典就是結果
一開始想用用二維數組,好像不好理解,字典好處理一點

『叄』 python 特定 行列 文本 統計 計數

#openfile
fin=open("file01.txt","r")
fout=open("file02.txt","w")
#init
count_AG=0
count_AT=0
count_AC=0
#datalines
forlineinfin:
dat_in=line.split()
ifdat_in[3]=="A"anddat_in[4]=="G":
count_AG+=1
ifdat_in[3]=="A"anddat_in[4]=="T":
count_AT+=1
ifdat_in[3]=="A"anddat_in[4]=="C":
count_AC+=1
#output
fout.write("count_AG:%s ",count_AG)
fout.write("count_AT:%s ",count_AT)
fout.write("count_AC:%s ",count_AC)
#closefile
fin.close()
fout.close()

『肆』 Python怎麼實現統計文本文件字數

#-*-coding:utf-8-*-
#把每句 的換行符沒有統計

f=open('test.html','r+')

num=0
foriinf.readlines():
num=num+len(i.strip())

print(num)

『伍』 python文本處理--統計

text=['3
','35
','5
','75
']
count=[0foriinrange(10)]
forlineintext:
line=int(line.strip())-1
index=line/10
count[index]+=1
printcount

#=>結果
[2,0,0,1,0,0,0,1,0,0]

這樣正好就第一位是1-10, 第四位是31-40.。

text是你從文件中讀取的內容。這個用open和readlines就可以完成了。

其中line = int(line.strip())-1是為了將每個index中的檢測范圍向上擴1,即本身第一位是0-9的,數字-1後,就能將1-10算入第一個中了。

『陸』 Python 統計並輸出文本文件中每行單詞個數和總單詞個數,即類似如下輸出:

摘要 "#include

『柒』 Python如何統計文本中各個詞性的數量

如果是統計文本中某個詞出現的數量就用循環遍歷讀取,匹配到一次,num+=1,最後print

『捌』 求解Python如何統計文本中各詞性的數量

importre
File=open('文本.txt',encoding='utf-8')
#讀取全部內容
s=File.readlines()
#轉化成字元串
s=str(s)
#統計'NN'的數量
NN=len(re.findall(r"'NN'",s))
print(NN)

『玖』 用python 將文本中的數據讀取,統計某個區間的個數,並將區間與個數存放在另一個文本里,這個要怎樣實現

代碼如下:

#coding=utf-8

#從文件中載入數據
defload_numbers(file):

numbers=[]

withopen(file,'r')asf:

forlineinf.readlines():

numbers.append(int(line))

returnnumbers


if__name__=='__main__':

#從文件data.txt中載入數字
numbers=load_numbers('data.txt')

#區間下限
min=10

#區間上限
max=30

#統計區間數字個數

cnt=0

forvalinnumbers:

#如果不要包含上下限,去掉=號
ifval>=minandval<=max:

cnt=cnt+1


#將結果保存到文件result.txt中

withopen('result.txt','w')asf:

f.write('[%d,%d],%d'%(min,max,cnt))


print('done.')

『拾』 python統計文本中有多少行

寫一個文本統計的腳本:計算並列印有關文本文件的統計數據,包括文件里包含多少個字元、行、單詞數,以及前10個出現次數最多的單詞按順序排列
import time
keep=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ','-',"'"]
stop_words=['the','and','i','to','of','a','you','my','that','in','she','he','her','his','it','be','was','had']
def normalize(s):
result=''
for c in s.lower():
if c in keep:
result+=c

閱讀全文

與python文本統計相關的資料

熱點內容
思科路由器命令明文加密 瀏覽:171
方舟生存進化伺服器如何改名字 瀏覽:892
央行數字貨幣app怎麼注冊 瀏覽:431
51單片機顯示時間 瀏覽:769
我的世界網易版怎麼壓縮地圖 瀏覽:682
qq小程序雲伺服器和 瀏覽:739
方舟伺服器怎麼玩才好玩 瀏覽:557
單片機的部件 瀏覽:621
編譯原理遍的過程 瀏覽:252
python讀取json字元串 瀏覽:62
ubuntu1404安裝php 瀏覽:634
lua能編譯嗎 瀏覽:118
思仙怎麼看伺服器 瀏覽:660
php微信圖片防盜鏈 瀏覽:800
安卓1怎麼讀音 瀏覽:297
農業app怎麼開通快捷支付 瀏覽:912
pythonredisdict 瀏覽:389
如何攻擊別人網賭伺服器 瀏覽:882
隱私與應用加密的圖案密碼 瀏覽:38
陳情令王一博解壓 瀏覽:39