I am attempting to get the dataframe names stored in the lists, iterating through 2 loops. Instead of getting the dataframe name itself like cat
or sunday
, I am getting the iterator name like df
.
def get_df_name(df):
name =[x for x in globals() if globals()[x] is df][0]
return name
cat = pd.DataFrame()
dog = pd.DataFrame()
sunday = pd.DataFrame()
monday = pd.DataFrame()
for df in [cat, dog]:
for df1 in [sunday, monday]:
print('---------')
print(get_df_name(df) + ' and ' + get_df_name(df1))
Currently my output is below
---------
df and df1
---------
df and df1
---------
df and df1
---------
df and df1
But I am expecting
---------
cat and sunday
---------
cat and monday
---------
dog and sunday
---------
dog and Monday