我有许多如下数据框:
weight=pd.read_csv('weight.csv',index_col=0)
inventory=pd.read_csv('inventory1.csv',index_col=0)
将存储在数组中:
df_array=[weight,inventory,etc]
随后作为参数传递给另一个函数。当我运行这个:
df_array[0]
我得到:
Out[15]:
C11 C12 C13 C21 C22 C23 C31 C32 C33
C1 1.00 1.00 1.00 1.50 2.00 2.50 2.50 3.0 3.50
C2 0.40 0.50 0.67 1.00 1.00 1.00 1.50 2.0 2.50
C3 0.28 0.33 0.40 0.40 0.50 0.67 1.00 1.0 1.00
这些是数据框权重的行和列。我想要的是df_array [0]将数据框的名称(权重)打印为不带引号的变量名称,我可以将其作为参数传递给另一个函数。可能吗?还是有其他选择吗?
最佳答案
我认为最好是使用dictionary of DataFrames
代替list of DataFrames
:
df_dict={'weight': weight,'inventory': inventory}
然后按
keys
选择:df1 = df_dict['weight']
关于python - 数据框名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48962435/