是否可以将 %who DataFrame 转换为 IPython Notebook 中的列表?

Is it possible to convert %who DataFrame to a list in IPython Notebook?

我知道魔术命令%who DataFrame 可以打印出工作区中的数据帧列表。我想知道是否可以将输出制作成一个列表供以后参考?

例如,

import pandas as pd
df_1 = pd.DataFrame()
df_2 = pd.DataFrame()
%who DataFrame

returns:

df_1     df_2

我尝试了 list(%who DataFrame)output = %who DataFrame 之类的东西,none 已经奏效了。

who 仅打印结果,它不会 return 您可以访问的任何内容(您需要拦截流)。但是你可以用 who_ls 来代替,这就是 who 所说的:

In [23]: df0 = pd.DataFrame()

In [24]: df1 = pd.DataFrame()

In [25]: w = %who DataFrame
df0  df1     

In [26]: w

In [27]: w = %who_ls DataFrame

In [28]: w
Out[28]: ['df0', 'df1']

In [29]: type(w)
Out[29]: list