Skip to content

Instantly share code, notes, and snippets.

@MarcDufresne
Created March 3, 2021 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcDufresne/570911b74b3e458e360d45acf913e943 to your computer and use it in GitHub Desktop.
Save MarcDufresne/570911b74b3e458e360d45acf913e943 to your computer and use it in GitHub Desktop.
Python Memory Snapshot Profiler
def profile(message: str = "Snapshot"):
padding_len = max(99 - len(message), 0)
print(f"{message} {'*' * padding_len}")
import pandas
from pympler import muppy, summary
all_objects = muppy.get_objects()
sum1 = summary.summarize(all_objects)
# Prints out a summary of the large objects
summary.print_(sum1)
dataframes = [ao for ao in all_objects if isinstance(ao, pandas.DataFrame)]
for d in dataframes:
print(d.columns.values)
print(len(d))
print("*" * 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment