Skip to content

Commit bf9e4f3

Browse files
ohahohahjorisvandenbossche
authored andcommitted
DOC: update the pd.DataFrame.memory_usage/empty docstring(Seoul) (#20102)
1 parent b97a5ad commit bf9e4f3

File tree

2 files changed

+82
-18
lines changed

2 files changed

+82
-18
lines changed

Diff for: pandas/core/frame.py

+72-16
Original file line numberDiff line numberDiff line change
@@ -2099,32 +2099,88 @@ def _sizeof_fmt(num, size_qualifier):
20992099
fmt.buffer_put_lines(buf, lines)
21002100

21012101
def memory_usage(self, index=True, deep=False):
2102-
"""Memory usage of DataFrame columns.
2102+
"""
2103+
Return the memory usage of each column in bytes.
2104+
2105+
The memory usage can optionally include the contribution of
2106+
the index and elements of `object` dtype.
2107+
2108+
This value is displayed in `DataFrame.info` by default. This can be
2109+
suppressed by setting ``pandas.options.display.memory_usage`` to False.
21032110
21042111
Parameters
21052112
----------
2106-
index : bool
2107-
Specifies whether to include memory usage of DataFrame's
2108-
index in returned Series. If `index=True` (default is False)
2109-
the first index of the Series is `Index`.
2110-
deep : bool
2111-
Introspect the data deeply, interrogate
2112-
`object` dtypes for system-level memory consumption
2113+
index : bool, default True
2114+
Specifies whether to include the memory usage of the DataFrame's
2115+
index in returned Series. If ``index=True`` the memory usage of the
2116+
index the first item in the output.
2117+
deep : bool, default False
2118+
If True, introspect the data deeply by interrogating
2119+
`object` dtypes for system-level memory consumption, and include
2120+
it in the returned values.
21132121
21142122
Returns
21152123
-------
21162124
sizes : Series
2117-
A series with column names as index and memory usage of
2118-
columns with units of bytes.
2119-
2120-
Notes
2121-
-----
2122-
Memory usage does not include memory consumed by elements that
2123-
are not components of the array if deep=False
2125+
A Series whose index is the original column names and whose values
2126+
is the memory usage of each column in bytes.
21242127
21252128
See Also
21262129
--------
2127-
numpy.ndarray.nbytes
2130+
numpy.ndarray.nbytes : Total bytes consumed by the elements of an
2131+
ndarray.
2132+
Series.memory_usage : Bytes consumed by a Series.
2133+
pandas.Categorical : Memory-efficient array for string values with
2134+
many repeated values.
2135+
DataFrame.info : Concise summary of a DataFrame.
2136+
2137+
Examples
2138+
--------
2139+
>>> dtypes = ['int64', 'float64', 'complex128', 'object', 'bool']
2140+
>>> data = dict([(t, np.ones(shape=5000).astype(t))
2141+
... for t in dtypes])
2142+
>>> df = pd.DataFrame(data)
2143+
>>> df.head()
2144+
int64 float64 complex128 object bool
2145+
0 1 1.0 (1+0j) 1 True
2146+
1 1 1.0 (1+0j) 1 True
2147+
2 1 1.0 (1+0j) 1 True
2148+
3 1 1.0 (1+0j) 1 True
2149+
4 1 1.0 (1+0j) 1 True
2150+
2151+
>>> df.memory_usage()
2152+
Index 80
2153+
int64 40000
2154+
float64 40000
2155+
complex128 80000
2156+
object 40000
2157+
bool 5000
2158+
dtype: int64
2159+
2160+
>>> df.memory_usage(index=False)
2161+
int64 40000
2162+
float64 40000
2163+
complex128 80000
2164+
object 40000
2165+
bool 5000
2166+
dtype: int64
2167+
2168+
The memory footprint of `object` dtype columns is ignored by default:
2169+
2170+
>>> df.memory_usage(deep=True)
2171+
Index 80
2172+
int64 40000
2173+
float64 40000
2174+
complex128 80000
2175+
object 160000
2176+
bool 5000
2177+
dtype: int64
2178+
2179+
Use a Categorical for efficient storage of an object-dtype column with
2180+
many repeated values.
2181+
2182+
>>> df['object'].astype('category').memory_usage(deep=True)
2183+
5168
21282184
"""
21292185
result = Series([c.memory_usage(index=False, deep=deep)
21302186
for col, c in self.iteritems()], index=self.columns)

Diff for: pandas/core/generic.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1489,12 +1489,20 @@ def __contains__(self, key):
14891489

14901490
@property
14911491
def empty(self):
1492-
"""True if NDFrame is entirely empty [no items], meaning any of the
1492+
"""
1493+
Indicator whether DataFrame is empty.
1494+
1495+
True if DataFrame is entirely empty (no items), meaning any of the
14931496
axes are of length 0.
14941497
1498+
Returns
1499+
-------
1500+
bool
1501+
If DataFrame is empty, return True, if not return False.
1502+
14951503
Notes
14961504
-----
1497-
If NDFrame contains only NaNs, it is still not considered empty. See
1505+
If DataFrame contains only NaNs, it is still not considered empty. See
14981506
the example below.
14991507
15001508
Examples

0 commit comments

Comments
 (0)