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 dataframe
df = pd.DataFrame({'AGE': [ 20, 29],
'HEIGHT': [94, 170],
'WEIGHT': [80, 115]})
# implementing the dataframe.values() function
print(df.values)

Explanation

  • Line 1: We import the pandas module.
  • Lines 4–6-: We create a dataframe, df.
  • Line 10: We implement the DataFrame.values attribute to obtain the NumPy values of df. Next, we print the value to the console.