Convert pandas dataframe to NumPy array

前端 未结 15 2372
别那么骄傲
别那么骄傲 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:45

    I went through the answers above. The "as_matrix()" method works but its obsolete now. For me, What worked was ".to_numpy()".

    This returns a multidimensional array. I'll prefer using this method if you're reading data from excel sheet and you need to access data from any index. Hope this helps :)

提交回复
热议问题