I'd like to make this code more elegant and reduced. I have three data frames that need to be combined to use Seaborn hue. I need to add a key for the hue itself.
This is what I have come up with, but I feel there must be a more elegant and efficient way
df = pd.DataFrame({ 'A' : range(3), 'B' : range(3) })
frames = (df.copy(), df.copy(), df.copy())
f_names = ["one", "two", "three"]
dff = pd.DataFrame()
for e, f in enumerate(frames):
tmp = f.copy()
tmp['name'] = f_names[e]
dff = dff.append(tmp, ignore_index=True)
print(dff)
Output:
A B name
0 0 0 one
1 1 1 one
2 2 2 one
3 0 0 two
4 1 1 two
5 2 2 two
6 0 0 three
7 1 1 three
8 2 2 three
thank you!