How can I construct a Pandas DataFrame from individual 1D Numpy arrays without copying

后端 未结 3 1557
青春惊慌失措
青春惊慌失措 2021-02-19 23:07

Unlike every other question I can find, I do not want to create a DataFrame from a homogeneous Numpy array, nor do I want to convert a structured array into a DataFrame.

3条回答
  •  臣服心动
    2021-02-19 23:43

    pandas.DataFrame ({"col": nparray, "col": nparray})
    

    This works if you try list (nparray) instead. Here's a generic example:

    import numpy as np
    import pandas as pd
    
    alpha = np.array ([1, 2, 3])
    beta = np.array ([4, 5, 6])
    gamma = np.array ([7, 8, 9])
    
    dikt = {"Alpha" : list (alpha), "Beta" : list (beta), "Gamma":list (gamma)}
    
    data_frame = pd.DataFrame (dikt)
    print (data_frame)
    

提交回复
热议问题