Convert Pandas DataFrame To Numpy Arrays
In this post, learn how to convert Pandas Dataframe to Numpy Arrays.
For this example, I will be using Iris dataset.
In [1]:
import pandas as pd
Let us read csv using Pandas.
In [3]:
df = pd.read_csv('datasets_19_420_Iris.csv')
In [4]:
df.head()
Out[4]:
There are two ways to convert dataframe to Numpy Array.
- df.to_numpy()
- df.values
df.to_numpy()
In [14]:
type(df.to_numpy())
Out[14]:
In [15]:
df.to_numpy()[0]
Out[15]:
df.values
In [13]:
type(df.values)
Out[13]:
In [16]:
df.values[0]
Out[16]:
Related Articles:
Related Notebooks
- How To Convert Python List To Pandas DataFrame
- How to Convert Python Pandas DataFrame into a List
- How to Sort Pandas DataFrame with Examples
- How to Export Pandas DataFrame to a CSV File
- 3 Ways to Rename Columns in Pandas DataFrame
- Python Pandas String To Integer And Integer To String DataFrame
- How To Append Rows With Concat to a Pandas DataFrame
- How To Drop One Or More Columns In Pandas Dataframe
- How To Iterate Over Rows In A Dataframe In Pandas