Last active
October 13, 2021 05:09
-
-
Save rchardptrsn/ae2f5e7817ccbf62e6cc1350a005dd3d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import sys | |
| import pandas as pd | |
| # Function to retrieve a list of Pandas DataFrames and their sizes in memory | |
| # Call the function: | |
| # pandas_dfs_in_memory(mydir=dir(),parent_vars=globals()) | |
| def pandas_dfs_in_memory(mydir,parent_vars): | |
| # get a list of all the local objects with sizes | |
| objects=[] | |
| for name,obj in parent_vars.items(): | |
| objects.append([name,sys.getsizeof(obj)]) | |
| # get a list of Pandas DataFrames | |
| alldfs=[] | |
| for var in mydir: | |
| if isinstance(parent_vars[var], pd.core.frame.DataFrame) and var[0]!='_': | |
| alldfs.append(var) | |
| # Print the objects and memory for DataFrames | |
| for i in objects: | |
| if i[0] in alldfs: | |
| print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment