Answers for "converting a pandas dataframe to a numpy array"

1

df to np array

df = pd.DataFrame({"A": [1, 2], "B": [3.0, 4.5]})
>>> df.to_numpy()
array([[1. , 3. ],
       [2. , 4.5]])
Posted by: Guest on January-28-2022
0

pandas series to numpy array

ser = pd.Series(pd.Categorical(['a', 'b', 'a']))
>>> ser.to_numpy()
array(['a', 'b', 'a'], dtype=object)
Posted by: Guest on November-15-2021

Code answers related to "converting a pandas dataframe to a numpy array"

Python Answers by Framework

Browse Popular Code Answers by Language