Pandas Get a List Of All Data Frames loaded into memory

前端 未结 3 524
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 19:01

I am using pandas to read several csv files into memory for processing and at some point would like to list all the data frames I have loaded into memory. Is there a simple

3条回答
  •  甜味超标
    2020-12-09 19:27

    You could list all dataframes with the following:

    import pandas as pd
    
    # create dummy dataframes
    df1 = pd.DataFrame({'Col1' : list(range(100))})
    df2 = pd.DataFrame({'Col1' : list(range(100))})
    
    # check whether all variables in scope are pandas dataframe. 
    # Dir() will return a list of string representations of the variables. 
    # Simply evaluate and test whether they are pandas dataframes
    alldfs = [var for var in dir() if isinstance(eval(var), pd.core.frame.DataFrame)]
    
    print(alldfs) # df1, df2
    

提交回复
热议问题