import pandas as pd a = pd.DataFrame({'task':['one'],'label':['tag_01'] }) b = pd.DataFrame({'task':['one'],'label':['tag_01'] }) c = pd.DataFrame({'task':['one'],'label':['tag_01'] }) d = pd.DataFrame({'task':['two'],'label':['tag_02'] })
A common solution to iterate over dataframes while using their name is to use another list with dataframes names, then enumerate and get value of name by position:
# create a dict containing dfs names = ['a','b','c'] dict_dfs = ({names[i]: df for i, df in enumerate([a, b, c])})
Now we can use globals() to generate desidered output. The globals() method returns the dictionary of the current global symbol table. A symbol table is a data structure maintained by a compiler.
for i in dict_dfs: globals()[str(i)] = pd.concat([dict_dfs[i], d], axis = 0)
Results:
a Out[1]: task label 0 one tag_01 0 two tag_02 b Out[2]: task label 0 one tag_01 0 two tag_02 c Out[3]: task label 0 one tag_01 0 two tag_02