Convert pandas series into numpy array [duplicate] Convert pandas series into numpy array [duplicate] numpy numpy

Convert pandas series into numpy array [duplicate]


To get numpy array, you need

Y.values


Try this:
after applying the .as_matrix on your series object

Y.reshape((2,1))

Since .as_matrix() only returns a numpy-array NOT a numpy-matrix.Link here


If df is your dataframe, then a column of the dataframe is a series and to convert it into an array,

df = pd.DataFrame()x = df.valuesprint(x.type)

The following prints,

<class 'numpy.ndarray'>

successfully converting it to an array.