w3resource

Pandas DataFrame: memory_usage() function

DataFrame - memory_usage() function

The memory_usage function is used to get the memory usage of each column in bytes.

The memory usage can optionally include the contribution of the index and elements of object dtype.

This value is displayed in DataFrame.info by default. This can be suppressed by setting pandas.options.display.memory_usage to False.

Syntax:

DataFrame.memory_usage(self, index=True, deep=False)

Parameters:

Name Description Type/Default Value Required / Optional
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 is the first item in the output. bool
Default Value: True
Required
deep  If True, introspect the data deeply by interrogating object dtypes for system-level memory consumption, and include it in the returned values. bool
Default Value: False
Required

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

Example:


Download the above Notebook from here.

Previous: DataFrame - shape property
Next: DataFrame - empty property