Python串列list元組tuple字典dictionary

程式碼

import csv                      #輸入csv套件comma separated value
file = open('SPY.CSV','r')     #打開下載的檔案SPY.CSV,模式是r讀取,
csvreader = csv.reader(file)   #將檔案讀入變數csvreader
header, rows = [], []           #宣告空白串列(陣列,清單)
header = next(csvreader)       #串列header儲存檔案第一列
for row in csvreader:          #檔案接續逐列附加append於rows串列
   rows.append(row)
file.close()             #關閉檔案
header.append('MA20')    #appendix附錄,為header串列list新曾元素
header.append('部位')
#print('印出前十列')
#print(header)
for i in range(20):
   rows[i].append(rows[i][5])
for i in range(21,len(rows)):
    sum20 = 0.0      #實數=浮點數
    for j in range(i-20, i):
       sum20 += float(rows[j][5])
    rows[i].append(sum20/20)
for i in range(len(rows)-3,len(rows)):  #length的命令len(rows)
    print('第',i+1,'列',rows[i])
239佘. 0330. excel,match,index. https://zxcv0218.blogspot.com/2024/03/excelmatchindex.html

留言

  1. https://wangjhihyu0207.blogspot.com/2024/04/pythonlisttupledictionary.html

    回覆刪除
  2. 作者已經移除這則留言。

    回覆刪除
  3. https://zxcv0218.blogspot.com/2024/04/pythonlisttupledictionary.html

    回覆刪除
  4. https://20020927.blogspot.com/2024/04/pythonelisttupledictionary.html

    回覆刪除
  5. D11017237
    https://gold-1-2zhang842.blogspot.com/2024/04/pythonlisttupledictionary.html

    回覆刪除
  6. D11017242李岳勳
    https://d11017242takming.blogspot.com/2024/04/pythonlisttupledictionary-4-14-2024.html

    回覆刪除
  7. https://zxcv901026.blogspot.com/2024/04/pythonlisttupledictionary.html

    回覆刪除
  8. https://ting1008finan.blogspot.com/2024/04/pythonlisttupledictionary.html

    回覆刪除
  9. D11017202吳睿捷https://draft.blogger.com/blog/post/edit/preview/6174802439427569065/6485643360567128012

    回覆刪除
  10. d11017363陳楷翔
    https://d11017363.blogspot.com/2024/04/pythonlisttupledictionary.html

    回覆刪除
  11. d11017350林莞婷
    https://bowlllll.blogspot.com/2024/04/pythonlisttupledictionary.html

    回覆刪除
  12. https://www.blogger.com/blog/post/edit/1552338610947827751/5990380313023439837

    回覆刪除
  13. https://jia-0909.blogspot.com/2024/04/pythonlisttupledictionary_21.html

    回覆刪除
  14. https://d11017218.blogspot.com/2024/04/pythonlisttupledictionary.html

    回覆刪除
  15. D11017311陳佑愷
    https://danley1116.blogspot.com/2024/04/pythonlisttupledictionary_21.html

    回覆刪除
  16. D11017160朱昱勳
    https://www.blogger.com/blog/post/edit/preview/3294357186626132669/5031546059039744579

    回覆刪除
  17. https://yu-han18.blogspot.com/2024/04/vs-code.html

    回覆刪除
  18. D11017156林毓荃
    https://www.blogger.com/u/1/blog/post/edit/preview/3294357186626132669/2010687410565177969

    回覆刪除
  19. https://www.blogger.com/blog/post/edit/8003165942710740669/3491271974116525950

    回覆刪除
  20. D11017157 陳名君
    https://takming12345.blogspot.com/2024/04/pythonlisttupledictionary.html

    回覆刪除
  21. D11017257蔡欣辰
    https://takming123.blogspot.com/2024/04/pythonlisttupledictionary.html

    回覆刪除
  22. D11017352 張弘陽
    https://35607161.blogspot.com/2024/06/pythonlisttupledictionary.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

馬可維茲風險平均數平面

賴青得python運算CSV輸出TKINTER投資風險與報酬Markowitz

劉任昌利用Python讀取SPY日成交資料(繳交作業情形)