Convert pandas dataframe to NumPy array

前端 未结 15 2342
别那么骄傲
别那么骄傲 2020-11-21 23:57

I am interested in knowing how to convert a pandas dataframe into a NumPy array.

dataframe:

import numpy as np
import pandas as pd

index = [1, 2, 3,         


        
15条回答
  •  广开言路
    2020-11-22 00:54

    Two ways to convert the data-frame to its Numpy-array representation.

    • mah_np_array = df.as_matrix(columns=None)

    • mah_np_array = df.values

    Doc: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.as_matrix.html

提交回复
热议问题