獲取 DataFrame 資訊和記憶體使用情況
要獲取有關 DataFrame 的基本資訊,包括列名和資料型別:
import pandas as pd
df = pd.DataFrame({'integers': [1, 2, 3],
'floats': [1.5, 2.5, 3],
'text': ['a', 'b', 'c'],
'ints with None': [1, None, 3]})
df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3 entries, 0 to 2
Data columns (total 4 columns):
floats 3 non-null float64
integers 3 non-null int64
ints with None 2 non-null float64
text 3 non-null object
dtypes: float64(2), int64(1), object(1)
memory usage: 120.0+ bytes
要獲取 DataFrame 的記憶體使用情況:
>>> df.info(memory_usage='deep')
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3 entries, 0 to 2
Data columns (total 4 columns):
floats 3 non-null float64
integers 3 non-null int64
ints with None 2 non-null float64
text 3 non-null object
dtypes: float64(2), int64(1), object(1)
memory usage: 234.0 bytes