劉任昌期末考

import csv #德明科大劉任昌修改11與16列
f = open('00960.csv','r',encoding='utf-8')
csv_reader = csv.reader(f)
header, rows = [], []        #宣告空白串列(陣列,清單)
header = next(csv_reader)     #串列header存放第一列標題
for row in csv_reader:        #逐列讀檔案、附加append於rows串列
   rows.append(row)
f.close()
idSet = set()
component = dict()
#zeros = [0 for i in range(21)] 
for row in rows:
    for j in range(0, 21):
        idSet.add(row[j*4])
for id in idSet:
    component[id] = [0 for i in range(21)] #取代原來的zeros
for row in rows:
    for j in range(0, 21):
        if row[j*4+3] != '':
            component[row[j*4]][j] = row[j*4 + 3]
            print(row[j*4+1],component[row[j*4]])
for id in idSet:
    print(id, component[id])

原來

修改後

留言

  1. https://hsiao-yu0711.blogspot.com/2026/06/blog-post_25.html

    回覆刪除
  2. https://huang-pei-kai.blogspot.com/2026/06/blog-post.html

    回覆刪除
  3. https://fanyahui.blogspot.com/2026/06/blog-post_25.html

    回覆刪除
  4. https://s10655075.blogspot.com/2026/06/blog-post.html

    回覆刪除
  5. https://stanley-ouo.blogspot.com/2026/06/blog-post.html

    回覆刪除
  6. https://d11217111.blogspot.com/2026/06/import-csv-1116-f-open00960.html

    回覆刪除
  7. https://lukelu0928.blogspot.com/2026/06/blog-post.html

    回覆刪除
  8. https://yiminglinn.blogspot.com/2026/06/blog-post.html

    回覆刪除
  9. https://11217133d.blogspot.com/2026/06/blog-post.html?m=1

    回覆刪除
  10. https://xuan0729.blogspot.com/2026/06/blog-post.html

    回覆刪除
  11. https://the-most-great.blogspot.com/2026/06/blog-post.html

    回覆刪除
  12. https://the-most-great-tony11.blogspot.com/2026/06/blog-post.html

    回覆刪除
  13. https://rubylinnn.blogspot.com/2026/06/blog-post.html

    回覆刪除
  14. https://laiweikaiaaa.blogspot.com/2026/06/blog-post.html

    回覆刪除
  15. https://hank20050328.blogspot.com/2026/06/blog-post.html

    回覆刪除
  16. https://yunn-xin.blogspot.com/2026/06/blog-post.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

劉任昌美國星期一假日法案,蒙地卡羅證券價格模擬

劉任昌蒙地卡羅模擬,遊戲驛站軋空事件

劉任昌「python讀入csv檔案計算黃金交叉和死亡交叉」