简体   繁体   English

将数据帧转换为二维数组

[英]convert Dataframe to 2d Array

I have a data-frame of size (140000,22) dimensions.我有一个大小为 (140000,22) 维度的数据框。

i have to create 2d array of equal dimensions to pass it into convolution neural network .我必须创建相同维度的二维数组才能将其传递到卷积神经网络中。

Can you please guide how to transform on this dataframe你能指导如何在这个数据帧上进行转换吗

You just need to call .values on the DataFrame.您只需要在.values上调用.values即可。

If for example your dataframe is called df , then you can pass df.values to your convolutional neural network.例如,如果您的数据df.values名为df ,那么您可以将df.values传递给您的卷积神经网络。

Use arr = df.to_numpy()使用arr = df.to_numpy()

See: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html请参阅: https : //pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html

It will create a 2d array where each row is the inner array.它将创建一个二维数组,其中每一行都是内部数组。

[[row1],
 [row2],
 [row3]...
 [row n]]

To turn it into a 2d array where each column is the inner array, use transpose:要将其转换为每列是内部数组的二维数组,请使用转置:

arr = np.transpose(arr)

[[all_data_in_col_1],
 [all_data_in_col_2],...
 [all_data_in_col_n]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM