湖濱散記部落格的樹心幽徑[login][主頁]
604:20200625用python設計讀檔程式來算帳

(1)如沒有python程式開發環境, 請參考如下文章來下載python-3.7.4-amd64.exe並安裝之。

20191014在windows7安裝並使用python3.7.4來剖析數字序列字串

 

(2-1) 參考如下文章設計輸入「嘸蝦米字根拆碼」查找對應中文字的python程式:

   20191120用PYTHON設計可輸入拆碼來搜尋Boshiamy.cin文字檔的程式readb.py

 

(2-2)如沒numpy 陣列模組,要安裝pip並用pip來裝numpy 陣列模組:

  python -m pip install --upgrade pip

  pip install numpy

 

(3)帳務資料檔為p6.dat下載 (2 KB) | created 25 六月, 2020



(4-1)在windows開始功能表執行IDLE(python 3.7 64bit)並按CTRL+N在PYTHON文字編輯器編寫如下程式碼並存為d:\readf.py

# -*- coding: UTF-8 -*-
import numpy as np
f = open("p6.dat",'r',encoding = 'utf-8')
c=0
line = f.readline()
while line:
    c=c+1
    bs=(' '.join(line.split())).split(',')
    print(c,bs[0],end=' ')
    cs = []
    for i in range(1,len(bs)):
       cs.append(int(bs[i]))
    maxno=30
    na=np.arange(maxno)
    for i in range(maxno):
       na[i]=0
    for i in cs:
        if i < maxno :
            na[i]=i;
    for i in range(1,maxno):
       print(na[i],end=',')
    print()
    line = f.readline()

f.close()


(4-2)按F5儲存編寫的程式並執行結果如下:(資料檔p6.dat要和本程式檔擺在同一個目錄下)

1 6/1(一),1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20,0,22,23,24,25,0,0,28,0,30,
2 6/4(四),0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,23,0,25,0,0,0,0,0,
3 6/8(一),0,0,3,4,5,6,7,0,9,0,11,0,13,0,0,0,0,18,19,0,21,22,0,24,25,26,27,28,29,0,
4 6/11(四),0,2,0,4,5,6,7,8,9,0,11,12,0,14,15,16,0,18,19,0,21,22,23,24,25,26,27,0,29,30,
5 6/15(一),0,2,3,4,5,6,7,0,9,0,0,0,13,0,15,0,17,18,19,20,0,22,23,24,0,26,27,28,29,30,
6 6/18(四),1,2,0,4,5,0,0,8,9,0,11,12,13,14,15,16,17,18,19,20,0,22,0,0,25,0,27,28,29,30,
7 6/22(一),1,0,0,4,0,6,7,0,9,0,11,12,0,14,15,16,17,0,19,20,0,22,23,24,25,0,27,0,29,30,
8 5/4(一),0,2,0,4,0,6,7,0,9,0,11,0,13,14,0,0,0,18,19,20,0,22,23,24,25,0,27,28,0,30,
9 5/5(二),0,2,3,4,5,6,7,0,9,0,11,0,13,0,15,16,17,18,19,20,0,22,23,24,0,0,27,0,0,0,
10 5/8(五)早,1,2,3,4,5,6,7,0,9,0,11,0,0,14,15,0,0,18,19,0,0,22,23,24,25,26,0,28,29,30,
11 5/8(五)放學,0,2,3,4,5,6,7,0,9,0,11,12,13,14,15,16,17,0,19,20,0,22,23,24,25,0,27,28,0,30,
12 5/11(一),0,2,3,0,5,0,7,8,9,0,0,12,13,14,15,16,17,18,19,20,21,22,23,0,25,26,27,28,29,30,
13 5/14(四),1,2,0,4,5,6,7,0,0,0,11,0,13,14,0,16,0,0,0,0,0,22,23,24,25,0,27,28,0,0,
14 5/18(一),1,2,3,0,5,0,0,0,9,0,11,12,13,14,15,0,17,18,19,20,0,22,23,0,25,26,27,28,29,0,
15 5/21(四),0,2,0,0,5,0,0,8,9,0,0,12,13,0,15,16,17,18,0,20,0,0,0,0,25,0,0,28,0,30,
16 5/26(二)下午大操場,0,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,0,0,19,20,0,0,23,24,25,26,27,0,29,30,
17 5/28(四),0,0,0,4,5,6,7,0,9,0,11,0,13,14,15,0,17,18,19,20,0,22,23,24,25,26,27,28,29,0,
18 4/30(四),1,2,0,0,5,6,7,8,9,0,11,0,13,14,15,16,0,18,19,20,21,22,23,24,25,26,27,28,29,0,
19 4/28(二)下午,0,0,3,4,5,6,7,8,9,0,0,0,13,14,15,0,17,18,19,0,0,22,23,24,25,26,27,28,29,30,
20 4/27(一)上午操場,1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20,0,22,23,24,25,26,27,28,29,30,
21 4/23(四),0,0,3,0,0,6,0,0,9,0,0,0,0,0,15,0,0,18,19,0,0,0,23,0,25,26,0,0,29,0,
22 4/21(二)上午操場,0,0,0,0,5,6,7,0,9,0,11,12,13,14,15,16,17,18,19,20,0,22,23,24,25,0,27,28,0,30,
23 4/21(二)下午操場,1,0,0,0,5,6,7,0,9,0,11,12,13,14,15,16,17,0,0,20,0,0,23,24,25,0,27,0,0,30,
24 4/20(一),1,2,3,0,0,6,0,8,9,10,11,12,13,0,15,16,17,18,19,0,0,22,23,24,25,0,27,28,0,30,
25 4/13(一),0,2,0,4,5,6,7,8,9,0,11,12,13,14,15,0,0,18,19,0,0,22,23,24,25,0,27,28,0,30,
26 4/7(二),0,0,0,4,5,6,7,8,0,0,11,12,13,14,15,16,17,18,19,20,0,0,23,24,0,0,27,28,0,30,
27 4/8(三),0,2,0,0,0,0,0,0,9,0,0,12,13,0,15,16,17,18,19,20,0,22,0,24,25,26,0,28,29,30,
28 3/31(三),1,2,0,4,0,6,0,8,9,0,11,0,0,14,15,0,0,18,19,20,0,22,0,24,25,0,27,0,29,0,
29 3/26(四),1,2,0,0,5,0,7,0,9,0,11,12,13,14,15,16,17,18,19,20,0,0,0,24,25,26,27,28,0,0,
30 3/23(一),0,0,0,4,5,6,7,0,0,0,11,0,0,14,0,0,0,0,0,0,0,0,0,24,0,0,27,0,0,0,
31 3/18(三),0,0,3,4,0,6,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,
32 3/16(一),0,2,3,4,0,6,7,8,9,0,0,0,13,14,0,16,17,0,0,20,0,22,23,0,0,26,27,28,29,30,
33 3/10(二),0,0,0,0,5,0,0,0,9,0,11,0,0,0,15,16,17,18,19,20,0,0,0,0,0,0,0,0,0,0,
34 3/11(三),0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,22,0,24,0,0,0,0,29,0,
35 3/9(一),0,2,0,4,5,6,7,0,9,0,11,0,0,14,15,16,17,18,19,20,0,22,0,0,25,26,27,28,0,30,
36 3/4(三),0,0,3,4,0,6,0,0,9,0,0,0,13,14,15,16,17,18,19,20,21,22,23,0,25,0,27,28,29,0,


(4-3)將(4-2)結果存檔為 p6out.csv下載 (3 KB) | created 25 六月, 2020

(4-4)用scalc載入上述結果檔p6out.csv,並統計處理之。

 

 

 


select id,article_id,topic,text from lt_articles_text where article_id =604; ok. update lt_articles set num_reads=num_reads +1 where id=604; ok.