IndigoChild
IndigoChild

Reputation: 844

Name of dataframe

I have many dataframes like the following:

weight=pd.read_csv('weight.csv',index_col=0)
inventory=pd.read_csv('inventory1.csv',index_col=0)

which are to be stored in an array:

df_array=[weight,inventory,etc]

to be passed as arguments subsequently, to another function. When I run this:

df_array[0]

I get:

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   

These are the rows and columns of the dataframe weight. What I want is for df_array[0] to print the name of the dataframe (weight) as a variable name without quotes which I can pass as argument to another function. Is it possible? Or is there any alternative for it?

Upvotes: 1

Views: 35

Answers (1)

jezrael
jezrael

Reputation: 862651

I think the best is use dictionary of DataFrames instead list of DataFrames:

df_dict={'weight': weight,'inventory': inventory}

and then select by keys:

df1 = df_dict['weight']

Upvotes: 1

Related Questions