pandas 1.4.2

ParametersReturnsBackRef
memory_usage(self, index: 'bool' = True, deep: 'bool' = False) -> 'Series'

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

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

Parameters

index : bool, default True

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.

deep : bool, default False

If True, introspect the data deeply by interrogating :None:None:`object` dtypes for system-level memory consumption, and include it in the returned values.

Returns

Series

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

Return the memory usage of each column in bytes.

See Also

Categorical

Memory-efficient array for string values with many repeated values.

DataFrame.info

Concise summary of a DataFrame.

Series.memory_usage

Bytes consumed by a Series.

numpy.ndarray.nbytes

Total bytes consumed by the elements of an ndarray.

Examples

This example is valid syntax, but we were not able to check execution
>>> dtypes = ['int64', 'float64', 'complex128', 'object', 'bool']
... data = dict([(t, np.ones(shape=5000, dtype=int).astype(t))
...  for t in dtypes])
... df = pd.DataFrame(data)
... df.head() int64 float64 complex128 object bool 0 1 1.0 1.0+0.0j 1 True 1 1 1.0 1.0+0.0j 1 True 2 1 1.0 1.0+0.0j 1 True 3 1 1.0 1.0+0.0j 1 True 4 1 1.0 1.0+0.0j 1 True
This example is valid syntax, but we were not able to check execution
>>> df.memory_usage()
Index           128
int64         40000
float64       40000
complex128    80000
object        40000
bool           5000
dtype: int64
This example is valid syntax, but we were not able to check execution
>>> df.memory_usage(index=False)
int64         40000
float64       40000
complex128    80000
object        40000
bool           5000
dtype: int64

The memory footprint of :None:None:`object` dtype columns is ignored by default:

This example is valid syntax, but we were not able to check execution
>>> df.memory_usage(deep=True)
Index            128
int64          40000
float64        40000
complex128     80000
object        180000
bool            5000
dtype: int64

Use a Categorical for efficient storage of an object-dtype column with many repeated values.

This example is valid syntax, but we were not able to check execution
>>> df['object'].astype('category').memory_usage(deep=True)
5244
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.frame.DataFrame.info pandas.core.series.Series.memory_usage

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/frame.py#3178
type: <class 'function'>
Commit: