Change language

Python | Pandas dataframe.memory_usage ()

The Pandas function dataframe.memory_usage() returns the memory usage of each column in bytes. Memory usage can optionally include the contribution of the index and the elements of the dtype object. This value is displayed in DataFrame.info by default.

Syntax: DataFrame.memory_usage (index = True, deep = False)

Parameters:
index: Specifies whether to include the memory usage of the DataFrame’s index in returned Series. If index = True the memory usage of the index the first item in the output.
deep: If True, introspect the data deeply by interrogating object dtypes for system-level memory consumption, and include it in the returned values.

Returns: A Series whose index is the original column names and whose values ​​is the memory usage of each column in bytes

To link to the CSV file used in the code, click here

Example # 1: Using the memory_usage () function prints memory usage information for each column in the data frame, along with index usage.

# import pandas as pd

import pandas as pd

 
# Create a data frame

df = pd.read_csv ( " nba.csv " )

  
# Print the data frame
df

Let’s use memory_usage () to find the memory usage for each column.

# Function to find memory usage of each
# column with index
# even if we don’t set index = True,
# it will show using the default index.

df.memory_usage (index = True )

Output:

Example # 2: Use memory_usage () to find the memory usage of each column, but not index.

# import pandas as pd

import pandas as pd

 
# Create a data frame

df = pd.read_csv ( "nba .csv "  )

 
# Function to find memory usage of each
# column but not index
# we set index = False

df.memory_usage (index = False )

Output:

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method