将数据帧列表与字符串列表关联的 Pythonic 方法

Yia*_*ian -1 python list depth-first-search pandas

在将 json 对象转换为 csv 时遇到此问题:

我现在有两个清单:

list_A 是字符串列表。每个字符串都是 df 的名称。

list_A = ['df1', 'df2', 'df3'] 
Run Code Online (Sandbox Code Playgroud)

list_B 有 3 个 pandas.core.frame.DataFrame 对象。

list_B[0] = [an entire df with columns, rows etc]
Run Code Online (Sandbox Code Playgroud)

什么代码可以确保一个列表中的字符串与另一个列表中的数据帧之间的关联,例如 df1 = list_B[0] 然后 df2 = list_B[1] 等等?

谢谢

tou*_*ody 5

您可以将它们与dict

df_dict = dict(zip(list_A, list_B))

df_dict['df1'].head() ## Returns the first 10 rows of list_B[0]
Run Code Online (Sandbox Code Playgroud)