I have array of dataframes:
a=[df1,df2,df3]
But I need the variable name as a string
b=['df1','df2','df3']
How can I do this?
>Solution :
Tooking inspiration from this answer,
you can solve your problem with the following code:
def get_var_name(variable):
for name in globals():
if eval(name) is variable:
return name
a = [df1, df2, df3]
b = [get_var_name(el) for el in a]
# print(b) gives ['df1', 'df2', 'df3']