Sunday 24 September 2023

How to Get the NumPy Representation of a Pandas DataFrame?

DataFrame values attribute return the Numpy representation of the DataFrame.

 

dataframe_values.py

import pandas as pd

# Create a sample DataFrame
data = {'Name': ['Krishna', 'Ram', 'Joel', 'Gopi', 'Jitendra', "Raj"],
        'Age': [34, 25, 29, 41, 52, 23],
        'City': ['Bangalore', 'Chennai', 'Hyderabad', 'Hyderabad', 'Bangalore', 'Chennai']}

df = pd.DataFrame(data)

print(df.values)

Output

[['Krishna' 34 'Bangalore']
 ['Ram' 25 'Chennai']
 ['Joel' 29 'Hyderabad']
 ['Gopi' 41 'Hyderabad']
 ['Jitendra' 52 'Bangalore']
 ['Raj' 23 'Chennai']]


Previous                                                 Next                                                 Home

No comments:

Post a Comment