Python按列和按行读取数据

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

 

你可能感兴趣的:(Python,数据预处理)