蘇宛閮利用Python讀取SPY日成交資料

傳統程式碼利用;或{}分指令或區段,刻意排版方便閱讀,PYTHON利用分行與所排當作指令 學過的電腦HTML, CSS, JAVASCRIPT, PYTHON

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])

執行結果

IPython 7.22.0 -- An enhanced Interactive Python.

runfile('C:/Users/user/Downloads/劉任昌.py', wdir='C:/Users/user/Downloads')
['日期', '成交量', '開', '高', '低', '收', '調收']
7833
['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']

runfile('C:/Users/user/Downloads/蘇宛閮.py', wdir='C:/Users/user/Downloads')
['日期', '成交量', '開', '高', '低', '收', '調收']
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. 蘇。https://jennysuwanting.blogspot.com/2025/06/pythoncsvtkintermarkowitz.html
    風險管理。https://jennysuwanting.blogspot.com/2025/06/blog-post.html
    https://jennysuwanting.blogspot.com/2025/05/csv.html
    428csv.https://jennysuwanting.blogspot.com/2025/04/pythoncsv.html
    https://jennysuwanting.blogspot.com/2025/04/500.html
    Excel.https://jennysuwanting.blogspot.com/2025/03/pythonexcel.html
    https://jennysuwanting.blogspot.com/2025/03/pythonspy.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

蘇宛閮期貨分析人員2025年第一次衍生性商品風險管理

蘇宛閮Python字典判斷除息日對照EXCEL向下填滿公式