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])
file = open('SPYW.CSV','w',newline='')
w = csv.writer(file) #寫入檔案 VScode是IDE(程式)整合開發環境
w.writerow(header) #第5列將檔案欄位名稱列header
w.writerows(rows) #第7列將檔案內容名稱rows
file.close()
https://d11017314.blogspot.com/2024/04/vscode.html
回覆刪除https://shiwanchun69.blogspot.com/2024/04/import-csv-csvcomma-separated-value.html
回覆刪除https://ryu2022.blogspot.com/2024/04/vs-code.html
回覆刪除https://d11017360.blogspot.com/2024/04/import-csv-csvcomma-separated-value.html
回覆刪除https://stephen-ky.blogspot.com/2024/04/vs-code.html
回覆刪除作者已經移除這則留言。
回覆刪除D11017157
回覆刪除https://takming12345.blogspot.com/2024/04/vs-code.html
https://dashyoure.blogspot.com/2024/04/vs-code.html
回覆刪除D11017257
回覆刪除https://takming123.blogspot.com/2024/04/vs-code.html
D11017242李岳勳
回覆刪除https://d11017242takming.blogspot.com/2024/04/vs-code.html
D11017237 張博宇
回覆刪除https://gold-1-2zhang842.blogspot.com/2024/04/vs-code.html
https://d11017353.blogspot.com/2024/04/blog-post.html
回覆刪除D11017311陳佑愷
回覆刪除https://danley1116.blogspot.com/2024/04/vs-code.html
作者已經移除這則留言。
回覆刪除https://liyuantsao.blogspot.com/2024/04/vs-code.html
回覆刪除D11017350林莞婷
回覆刪除https://bowlllll.blogspot.com/2024/04/vs-code.html
https://wangjhihyu0207.blogspot.com/2024/04/blog-post.html
回覆刪除D11017319 楊翔宇
回覆刪除https://yanghsiangyu.blogspot.com/2024/04/vs-code.html
D11017108
回覆刪除https://jia-0909.blogspot.com/2024/04/vs-code.html
D11017331 林巧涵
回覆刪除https://dwikko.blogspot.com/2024/04/vscode.html
D11017346蔣安恆金三丙
回覆刪除https://michael-an46.blogspot.com/2024/04/vscode.html
https://asdfghjk123666.blogspot.com/2024/04/123456.html
回覆刪除D11017153王芷榆
回覆刪除https://wangjhihyu0207.blogspot.com/2024/04/blog-post.html
D11017363陳楷翔
回覆刪除https://d11017363.blogspot.com/2024/04/vs-code.html
D11017125
回覆刪除https://you-rong.blogspot.com/2024/04/vs-code.html
金三乙洪均諺D11017243
回覆刪除https://yan911222.blogspot.com/2024/04/vscode.html
D11017202吳睿捷https://draft.blogger.com/blog/post/edit/preview/6174802439427569065/4542986923706524623
回覆刪除d11017318張雅琪
回覆刪除https://www.blogger.com/blog/post/edit/6727610962363206601/210300274143108525
D11017138林敦奕
回覆刪除https://as81162062.blogspot.com/2024/04/vs-code.html
D11017155吳怡萱
回覆刪除https://wuyixuannn.blogspot.com/2024/04/vs-code.html
D11017149秦詩婕
回覆刪除https://jasmine4132231.blogspot.com/2024/04/vs-code.html
D11017325田庭聿
回覆刪除https://www.blogger.com/blog/post/edit/9184636239191223707/2279911280614646445
https://liu-shih-kuan.blogspot.com/2024/04/import-csv-csvcomma-separated-value.html
回覆刪除D11017140黃思齊
回覆刪除https://d11017140.blogspot.com/2024/04/vs-code.html
D11017105 劉士寬
回覆刪除https://liu-shih-kuan.blogspot.com/2024/04/import-csv-csvcomma-separated-value.html
https://the-most-beeaut.blogspot.com/2024/04/blog-post.html
回覆刪除https://www.blogger.com/blog/post/edit/preview/1693244505491820496/8591225784118847885
回覆刪除D11017246 許書昀
回覆刪除https://shuooooooo.blogspot.com/2024/04/vs-code_21.html