程式碼
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
https://wangjhihyu0207.blogspot.com/2024/04/pythonlisttupledictionary.html
回覆刪除作者已經移除這則留言。
回覆刪除https://zxcv0218.blogspot.com/2024/04/pythonlisttupledictionary.html
回覆刪除https://20020927.blogspot.com/2024/04/pythonelisttupledictionary.html
回覆刪除D11017237
回覆刪除https://gold-1-2zhang842.blogspot.com/2024/04/pythonlisttupledictionary.html
D11017242李岳勳
回覆刪除https://d11017242takming.blogspot.com/2024/04/pythonlisttupledictionary-4-14-2024.html
https://zxcv901026.blogspot.com/2024/04/pythonlisttupledictionary.html
回覆刪除https://ting1008finan.blogspot.com/2024/04/pythonlisttupledictionary.html
回覆刪除D11017202吳睿捷https://draft.blogger.com/blog/post/edit/preview/6174802439427569065/6485643360567128012
回覆刪除d11017363陳楷翔
回覆刪除https://d11017363.blogspot.com/2024/04/pythonlisttupledictionary.html
d11017350林莞婷
回覆刪除https://bowlllll.blogspot.com/2024/04/pythonlisttupledictionary.html
https://www.blogger.com/blog/post/edit/1552338610947827751/5990380313023439837
回覆刪除https://jia-0909.blogspot.com/2024/04/pythonlisttupledictionary_21.html
回覆刪除https://d11017218.blogspot.com/2024/04/pythonlisttupledictionary.html
回覆刪除D11017311陳佑愷
回覆刪除https://danley1116.blogspot.com/2024/04/pythonlisttupledictionary_21.html
作者已經移除這則留言。
回覆刪除D11017160朱昱勳
回覆刪除https://www.blogger.com/blog/post/edit/preview/3294357186626132669/5031546059039744579
https://yu-han18.blogspot.com/2024/04/vs-code.html
回覆刪除D11017156林毓荃
回覆刪除https://www.blogger.com/u/1/blog/post/edit/preview/3294357186626132669/2010687410565177969
https://www.blogger.com/blog/post/edit/8003165942710740669/3491271974116525950
回覆刪除D11017157 陳名君
回覆刪除https://takming12345.blogspot.com/2024/04/pythonlisttupledictionary.html
D11017257蔡欣辰
回覆刪除https://takming123.blogspot.com/2024/04/pythonlisttupledictionary.html
D11017352 張弘陽
回覆刪除https://35607161.blogspot.com/2024/06/pythonlisttupledictionary.html