Python按列和按行讀取資料
阿新 • • 發佈:2019-02-02
def data_transform(heading, value): """ 按列讀取 """ data_length = len(value) ticker_length =len(heading)-1 value_list=[] ticker_list =[] date_list =[] for i in range(ticker_length): value_list.extend(value[:,i+1]) //按列讀取 date_list.extend(value[:,0]) ticker =repeat(heading[i+1], data_length) ticker_list.extend(ticker) length = len(value_list) ticker_list =np.array(ticker_list).reshape(length,1) date_list = np.array( date_list).reshape(length,1) value_list = np.array(value_list).reshape(length,1) list_con = np.concatenate((ticker_list, date_list),axis=1) //陣列連線 list_con = np.concatenate((list_con, value_list), axis=1) #print(list_con) #print(len(value_list)) #print(len(date_list)) return list_con """ 按行讀取 """ def data_transform(heading, value): data_length = len(value) ticker_length =len(heading)-1 value_list=[] ticker_list =[] date_list =[] for i in range(ticker_length): value_list.extend(value[i+1]) //按行讀取 date_list.extend(value[:,0]) ticker =repeat(heading[i+1], data_length) ticker_list.extend(ticker) length = len(value_list) ticker_list =np.array(ticker_list).reshape(length,1) date_list = np.array( date_list).reshape(length,1) value_list = np.array(value_list).reshape(length,1) list_con = np.concatenate((ticker_list, date_list),axis=1) //陣列連線 list_con = np.concatenate((list_con, value_list), axis=1) #print(list_con) #print(len(value_list)) #print(len(date_list)) return list_con