李俊誼利用Python讀取SPY日成交資料

PYTHON程式碼

#李俊誼利用Python讀取SPY日成交資料
#下載csv檔案下載CSV檔案 https://drive.google.com/file/d/1eB8B...
#李俊誼
import csv #輸入套件csv=comma seperated 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()            #關閉檔案
print(header)
print(len(rows))
print('全球第一檔ETF交易資料')
print(rows[0])
print(rows[len(rows)-1])

執行結果

runfile('C:/Users/user/Downloads/李俊誼.py', wdir='C:/Users/user/Downloads')
['日', '量', '開', '高', '低', '收', '率', '調']
8091
全球第一檔ETF交易資料
['1993/1/29', '1003200', '43.96875', '43.96875', '43.75', '43.9375', '0', '24.53 ']
['2025/3/20', '62958200', '563.33', '570.57', '562.6012', '565.49', '-0.29%', '565.49']

使用spyder

鑲入影片

留言

  1. https://leo1050317.blogspot.com/2025/06/60.html
    https://leo1050317.blogspot.com/2025/04/pythoncsv.html
    https://leo1050317.blogspot.com/2025/04/500spy.html
    https://leo1050317.blogspot.com/2025/03/pythoncsvspdr500etf19931292525320.html
    https://leo1050317.blogspot.com/2025/03/h1background-colorpurplecolorwhitepaddi.html
    風險管理https://leo1050317.blogspot.com/2025/06/blog-post.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

李俊誼風險管理期末考

李俊誼期末考60分

李俊誼Python讀取CSV檔案SPDR標普500ETF在1993/1/29至2525/3/20