2016-12-13 20 views
3

我使用熊貓將幾個csv文件讀入內存進行處理,並且在某些時候想要列出所有已加載到內存中的數據幀。有沒有簡單的方法來做到這一點? (我想類似%2!但只爲我在內存有可用的數據幀)熊貓獲取所有加載到內存中的數據幀的列表

+0

你在單獨的變量捕捉這些dataframes,或在某種容器中? –

+0

每個文件都作爲一個單獨的變量加載。 – Kartik

回答

6

你可以列出所有dataframes下列要求:

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