Skip to content

Commit 5b0caf4

Browse files
lebigotjorisvandenbossche
authored andcommitted
DOC: update the Series.memory_usage() docstring (pandas-dev#20086)
1 parent 9fb7ac9 commit 5b0caf4

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

pandas/core/series.py

+39-13
Original file line numberDiff line numberDiff line change
@@ -2765,28 +2765,54 @@ def reindex_axis(self, labels, axis=0, **kwargs):
27652765
return self.reindex(index=labels, **kwargs)
27662766

27672767
def memory_usage(self, index=True, deep=False):
2768-
"""Memory usage of the Series
2768+
"""
2769+
Return the memory usage of the Series.
2770+
2771+
The memory usage can optionally include the contribution of
2772+
the index and of elements of `object` dtype.
27692773
27702774
Parameters
27712775
----------
2772-
index : bool
2773-
Specifies whether to include memory usage of Series index
2774-
deep : bool
2775-
Introspect the data deeply, interrogate
2776-
`object` dtypes for system-level memory consumption
2776+
index : bool, default True
2777+
Specifies whether to include the memory usage of the Series index.
2778+
deep : bool, default False
2779+
If True, introspect the data deeply by interrogating
2780+
`object` dtypes for system-level memory consumption, and include
2781+
it in the returned value.
27772782
27782783
Returns
27792784
-------
2780-
scalar bytes of memory consumed
2781-
2782-
Notes
2783-
-----
2784-
Memory usage does not include memory consumed by elements that
2785-
are not components of the array if deep=False
2785+
int
2786+
Bytes of memory consumed.
27862787
27872788
See Also
27882789
--------
2789-
numpy.ndarray.nbytes
2790+
numpy.ndarray.nbytes : Total bytes consumed by the elements of the
2791+
array.
2792+
DataFrame.memory_usage : Bytes consumed by a DataFrame.
2793+
2794+
Examples
2795+
--------
2796+
2797+
>>> s = pd.Series(range(3))
2798+
>>> s.memory_usage()
2799+
104
2800+
2801+
Not including the index gives the size of the rest of the data, which
2802+
is necessarily smaller:
2803+
2804+
>>> s.memory_usage(index=False)
2805+
24
2806+
2807+
The memory footprint of `object` values is ignored by default:
2808+
2809+
>>> s = pd.Series(["a", "b"])
2810+
>>> s.values
2811+
array(['a', 'b'], dtype=object)
2812+
>>> s.memory_usage()
2813+
96
2814+
>>> s.memory_usage(deep=True)
2815+
212
27902816
"""
27912817
v = super(Series, self).memory_usage(deep=deep)
27922818
if index:

0 commit comments

Comments
 (0)