陳瑀晞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
嵌入影片
CSS的指令
<STYLE>H1{BACKGROUND-COLOR:PURPLE;COLOR:WHITE;PADDING:5PX;}PRE{BORDER:3PX RED SOLID;FONT-SIZE:1.5EM;}</STYLE>
https://chen-yu-hsi.blogspot.com/2025/06/pythoncsvtkintermarkowitz.html
回覆刪除321開始繳交作業。https://chen-yu-hsi.blogspot.com/2025/06/pythoncsvtkintermarkowitz.html