Alex
Alex

Reputation: 1537

Convert Pandas rows into a matrix of arrays

I want to convert each row from a pandas dataframe into an array, and then create a matrix with them.

I know how to do it with columns:

X = np.matrix([df['colA'].values,
 df['ColB'].values])

How can I do it by columns?

More details:

this is a sample of my dataframe: enter image description here

The output I want is this (please do not pay attention to the digits now):

[[36.10062, -115.2948],  #row 0
 [36.10062, -116.2948],  #row 1
 [34.10062, -112.2948],  #row 2
 [38.10062, -111.2948]]  #row 3

Upvotes: 0

Views: 1772

Answers (1)

Shrirang
Shrirang

Reputation: 1336

Pandas dataframe already have solution for this.

df.values

Upvotes: 2

Related Questions