How to show the NumPy representation of a dataframe in Pandas
Overview
In Pandas, the DataFrame.values attribute is used to return the NumPy representation of a given dataframe.
Syntax
DataFrame.values
Syntax for the DataFrame.values attribute
Parameters
This attribute takes no parameter value.
Return value
This attribute returns the values of a given dataframe.
Example
import pandas as pd# creating a dataframedf = pd.DataFrame({'AGE': [ 20, 29],'HEIGHT': [94, 170],'WEIGHT': [80, 115]})# implementing the dataframe.values() functionprint(df.values)
Explanation
- Line 1: We import the
pandasmodule. - Lines 4–6-: We create a dataframe,
df. - Line 10: We implement the
DataFrame.valuesattribute to obtain the NumPy values ofdf. Next, we print the value to the console.