邱宥蓁Python套件CSY比較EXCEL



import csv #輸入csv套件comma separated value file = open('TWSE.CSV','r',encoding='utf-8') #打開下載的檔案TWSE.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) for i in range(6): print('輸出第', i,'公司: ',rows[i-1]) print('台灣證劵交易所公司家數', len(rows)) print('排在最後', rows[-1])

留言

這個網誌中的熱門文章

邱宥蓁python維基百科

邱宥蓁pythotn例外處理try:...except:...

邱宥蓁python+tkinter輸入方塊的Return事件