楊侑宸利用Python讀取SPY日成交資料

PYTHON程式碼

#下載csv檔案下載CSV檔案 https://drive.google.com/file/d/1eB8B...
#劉任昌
import csv #輸入套件csv=comma seperated value                     #輸入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()            #關閉檔案
print(header)
print(len(rows))
print('全球第一檔ETF交易資料')
print(rows[0])
print(rows[len(rows)-1])

執行結果

Python 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 7.22.0 -- An enhanced Interactive Python.

runfile('C:/Users/user/Desktop/新增資料夾/temp7.py', wdir='C:/Users/user/Desktop/新增資料夾')
['日期', '成交量', '開', '高', '低', '收', '調收']
7833
全球第一檔ETF交易資料
['1993/1/29', '1003200', '43.96875', '43.96875', '43.75', '43.9375', '24.840673']
['2024/3/8', '86425500', '515.460022', '518.219971', '511.130005', '511.720001', '511.720001']

使用spyder

嵌入影片

留言

  1. 410etf.https://yangyoyo0125.blogspot.com/2025/04/500spy.html
    https://yangyoyo0125.blogspot.com/2025/03/pythoncsvspdr500etf19931292025320.html
    https://yangyoyo0125.blogspot.com/2025/03/pythonspy.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

楊侑宸金融常識測驗期中考

楊侑宸python運算CSV輸出TKINTER投資風險與報酬Markowaitz

楊侑宸HTML按鈕BUTTON事件ONCLICK 4月 21, 2025