numpy中的普通讀取:數組
1 import numpy as np 2 #skiprows能夠跳過前幾行數據,np.loadtxt方法直接將數據讀取到data數組中 3 data = np.loadtxt(open("路徑.csv","rb"),delimiter=",",skiprows=0)
讀取Excel:app
1 from openpyxl import load_workbook 2 #讀取路徑 3 book = load_workbook(filename=r"路徑.xlsx") 4 #讀取名字爲Sheet1的表 5 sheet = book.get_sheet_by_name("Sheet1") 6 #用於存儲數據的數組 7 data= [] 8 row_num = 1 9 while row_num <= 100 : 10 #將表中第一列的1-100行數據寫入data數組中 11 data.append(sheet.cell(row=row_num, column=1).value) 12 row_num = row_num + 1