-1

I have 3 columns in my df

enter image description here

How can i convert this to a matrix? I tried

numpy_matrix=df.as_matrix()

but this doenst give a matrix

CyberCube
  • 159
  • 3
  • 11

2 Answers2

1

In pandas 0.24.0+, it is recommended that you use to_numpy. The function as_matrix was deprecated in pandas 0.23.0.

df.to_numpy()
Antje
  • 73
  • 4
Scott Boston
  • 147,308
  • 15
  • 139
  • 187
1

To convert a pandas dataframe (df) to a numpy ndarray, use this code:

df = df.values

df now becomes the numpy ndarray:

Hasee Amarathunga
  • 1,901
  • 12
  • 17