Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.memory_usage#

DataFrame.memory_usage(index=True,deep=False)[source]#

Return the memory usage of each column in bytes.

The memory usage can optionally include the contribution ofthe index and elements ofobject dtype.

This value is displayed inDataFrame.info by default. This can besuppressed by settingpandas.options.display.memory_usage to False.

Parameters:
indexbool, default True

Specifies whether to include the memory usage of the DataFrame’sindex in returned Series. Ifindex=True, the memory usage ofthe index is the first item in the output.

deepbool, default False

If True, introspect the data deeply by interrogatingobject dtypes for system-level memory consumption, and includeit in the returned values.

Returns:
Series

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

See also

numpy.ndarray.nbytes

Total bytes consumed by the elements of an ndarray.

Series.memory_usage

Bytes consumed by a Series.

Categorical

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

DataFrame.info

Concise summary of a DataFrame.

Notes

See theFrequently Asked Questions for moredetails.

Examples

>>>dtypes=['int64','float64','complex128','object','bool']>>>data=dict([(t,np.ones(shape=5000,dtype=int).astype(t))...fortindtypes])>>>df=pd.DataFrame(data)>>>df.head()   int64  float64            complex128  object  bool0      1      1.0              1.0+0.0j       1  True1      1      1.0              1.0+0.0j       1  True2      1      1.0              1.0+0.0j       1  True3      1      1.0              1.0+0.0j       1  True4      1      1.0              1.0+0.0j       1  True
>>>df.memory_usage()Index           128int64         40000float64       40000complex128    80000object        40000bool           5000dtype: int64
>>>df.memory_usage(index=False)int64         40000float64       40000complex128    80000object        40000bool           5000dtype: int64

The memory footprint ofobject dtype columns is ignored by default:

>>>df.memory_usage(deep=True)Index            128int64          40000float64        40000complex128     80000object        180000bool            5000dtype: int64

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

>>>df['object'].astype('category').memory_usage(deep=True)5244

[8]ページ先頭

©2009-2025 Movatter.jp