简体   繁体   中英

How to convert dataframe into numpy array?

So I am currently making a neural network MLP (Multi-layer-Perceptron) on group classification on sea turtle speed between beach to sea on the seconds unit, and it looks somewhat like this.

在此处输入图像描述

Now on my Jupyter Notebook I type the following

data = pd.read_csv("SeaTurtles.csv")
data

It shows the data in dataframe

在此处输入图像描述

What I wanted to do is to separate these two groups which are group A for "Training" data and group B for "Testing" data. I wanted to convert the dataframe into a NumPy array so that it would make it easier for me to classify them into the SpeciesCode. So I type in:

newdf=data.drop(['Group1','Group 2'], axis = 1)
newdf

在此处输入图像描述

I need to split it into two test group A and B so I typed in

groupA=newdf.loc[newdf['Test*'] == 'A']
groupB=newdf.loc[newdf['Test*'] == 'B']

在此处输入图像描述

Group B 在此处输入图像描述

What I did was to convert these into numpy array with.to_numpy()

groupA = groupA.to_numpy()
groupA

and it returns the "AttributeError: 'numpy.ndarray' object has no attribute 'to_numpy' " 在此处输入图像描述

My question is did I do something wrong or is there another way for me to convert this dataframe into numpy array so that I can start training the data? Thank you in advance.

Pandas dataframe is a two-dimensional data structure to store and retrieve data in rows and columns format.

You can convert pandas dataframe to numpy array using the df.to_numpy() method.

You can use the below code snippet to convert pandas dataframe into numpy array. numpy_array = df.to_numpy() print(type(numpy_array))

Output:

<class 'numpy.ndarray'>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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