From 5b0caf46124ee5f268b317c7f9c5dcbf7d05e1dd Mon Sep 17 00:00:00 2001 From: "Eric O. LEBIGOT (EOL)" Date: Sat, 10 Mar 2018 17:32:20 +0100 Subject: [PATCH] DOC: update the Series.memory_usage() docstring (#20086) --- pandas/core/series.py | 52 ++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 0d1145961e79e..7b9b8a7a75008 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2765,28 +2765,54 @@ def reindex_axis(self, labels, axis=0, **kwargs): return self.reindex(index=labels, **kwargs) def memory_usage(self, index=True, deep=False): - """Memory usage of the Series + """ + Return the memory usage of the Series. + + The memory usage can optionally include the contribution of + the index and of elements of `object` dtype. Parameters ---------- - index : bool - Specifies whether to include memory usage of Series index - deep : bool - Introspect the data deeply, interrogate - `object` dtypes for system-level memory consumption + index : bool, default True + Specifies whether to include the memory usage of the Series index. + deep : bool, default False + If True, introspect the data deeply by interrogating + `object` dtypes for system-level memory consumption, and include + it in the returned value. Returns ------- - scalar bytes of memory consumed - - Notes - ----- - Memory usage does not include memory consumed by elements that - are not components of the array if deep=False + int + Bytes of memory consumed. See Also -------- - numpy.ndarray.nbytes + numpy.ndarray.nbytes : Total bytes consumed by the elements of the + array. + DataFrame.memory_usage : Bytes consumed by a DataFrame. + + Examples + -------- + + >>> s = pd.Series(range(3)) + >>> s.memory_usage() + 104 + + Not including the index gives the size of the rest of the data, which + is necessarily smaller: + + >>> s.memory_usage(index=False) + 24 + + The memory footprint of `object` values is ignored by default: + + >>> s = pd.Series(["a", "b"]) + >>> s.values + array(['a', 'b'], dtype=object) + >>> s.memory_usage() + 96 + >>> s.memory_usage(deep=True) + 212 """ v = super(Series, self).memory_usage(deep=deep) if index: