Skip to content

Instantly share code, notes, and snippets.

@mh0w
Last active January 10, 2024 17:31
Show Gist options
  • Save mh0w/96d69fe3e873396875432540397b495a to your computer and use it in GitHub Desktop.
Save mh0w/96d69fe3e873396875432540397b495a to your computer and use it in GitHub Desktop.
check object size
"""
sys:
Return the size of an object in bytes.The object can be any type of object.
All built-in objects will return correct results, but this does not have to
hold true for third-party extensions as it is implementation specific.
pandas/polars:
Returns the size of an object in KB/MB/GB. Checking the dtypes will be
informative (e.g., float64 likely to use more space than int8).
"""
import sys
s = "abcdef"
sys.getsizeof(s) #55
# Pandas
my_df.info(verbose=False, memory_usage="deep")
my_df.dtypes
# Polars
my_df.estimated_size()
my_df.dtypes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment