Convert two numpy array to dataframe

前端 未结 1 1315
北荒
北荒 2021-01-02 15:26

I want to convert two numpy array to one DataFrame containing two columns. The first numpy array \'images\' is of shape 102, 1024. The second numpy

相关标签:
1条回答
  • 2021-01-02 16:11

    You can't stack them easily, especially if you want them as different columns, because you can't insert a 2D array in one column of a DataFrame, so you need to convert it to something else, for example a list.

    So something like this would work:

    import pandas as pd
    import numpy as np
    images = np.array(images)
    label = np.array(label)
    dataset = pd.DataFrame({'label': label, 'images': list(images)}, columns=['label', 'images'])
    

    This will create a DataFrame with 1020 rows and 2 columns, where each item in the second column contains 1D arrays of length 1024.

    0 讨论(0)
提交回复
热议问题