Computer Engineering/Data Engineering
Pandas dataframe 메모리 사용량 확인하기
jordan.bae
2022. 12. 2. 22:23
Pandas의 dataframe 및 각 column의 메모리를 체크하는 방법은 매우 간단합니다.
dataframe 전체 메모리
dataframe.info() 메서드를 이용하면 맨 아래 memory usage가 출력됩니다.
>>> df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 173511 entries, 0 to 173510
Data columns (total 47 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 id 173511 non-null int64
1 created_at 173511 non-null datetime64[ns]
2 updated_at 173511 non-null datetime64[ns]
3 deleted_at 0 non-null datetime64[ns]
....
dtypes: datetime64[ns](4), float64(6), int64(4), object(33)
memory usage: 62.2+ MB
dataframe column 별 메모리
dataframe.memory_usage()함수를 통해 byte단위로 확인이 가능합니다.
위에 created_at row수가 173,511이고 1388088 byte이니깐 하나의 row에 8byte인 것을 볼 수 있습니다.
>>> df.memory_usage()
Index 128
id 1388088
created_at 1388088
updated_at 1388088
....
반응형