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
我个人认为this方法更好(如果在ipython中)。
基于以前的答案。。。 这将返回一个列表
但是,如果你试着运行一个脚本,它就不工作了
因此
因为有些数据帧只有一个副本供内部使用,并且这些副本以'\u'开头
您可以列出具有以下内容的所有数据帧:
相关问题 更多 >
编程相关推荐