티스토리 뷰

Python

Pandas dataframe 용량 줄이기

혬몰리 2023. 12. 19. 10:35
SMALL
  • 상황 : pandas dataframe의 용량이 커서 그런지, 데이터 가공 코드를 실행할 때마다 시간이 오래 걸림.
  • 실제 문제 해결 방법
    • pandas dataframe은 default로 64bit의 데이터타입들을 활용함 (예: float64, int64)
    • 데이터 범위에 맞춰서 줄여서 메모리 크기를 대폭 줄임
import numpy as np
data['column'] = data['column'].astype(np.int32)
  • 참고 자료
    • 아래 범위에 맞게 적절한 데이터 타입 선정 후 타입 변경 추천
Data type Description
bool_ Boolean (True or False) stored as a byte
int_ Default integer type (same as C long; normally either int64 or int32)
intc Identical to C int (normally int32 or int64)
intp Integer used for indexing (same as C ssize_t; normally either int32 or int64)
int8 Byte (-128 to 127)
int16 Integer (-32768 to 32767)
int32 Integer (-2147483648 to 2147483647)
int64 Integer (-9223372036854775808 to 9223372036854775807)
uint8 Unsigned integer (0 to 255)
uint16 Unsigned integer (0 to 65535)
uint32 Unsigned integer (0 to 4294967295)
uint64 Unsigned integer (0 to 18446744073709551615)
float_ Shorthand for float64.
float16 Half precision float: sign bit, 5 bits exponent, 10 bits mantissa
float32 Single precision float: sign bit, 8 bits exponent, 23 bits mantissa
float64 Double precision float: sign bit, 11 bits exponent, 52 bits mantissa
complex_ Shorthand for complex128.
complex64 Complex number, represented by two 32-bit floats
complex128 Complex number, represented by two 64-bit floats
반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함