Created
March 3, 2021 20:37
-
-
Save MarcDufresne/570911b74b3e458e360d45acf913e943 to your computer and use it in GitHub Desktop.
Python Memory Snapshot Profiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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