Following on an earlier question
I have
df1 = pd.Dataframe(
[
{'a': 1},
{'a': 2},
{'a': 3},
]
)
df2 = pd.Dataframe(
[
{'a': 4},
{'a': 5},
]
)
And I want
df_id a
1 1
2
3
2 4
5
I accepted an answer too soon, that told me to do
pd.concat([df1, df2], keys=[1,2])
which gives the correct result, but [1,2] is hardcoded.
I also want this to be incremental, meaning given
df3
df_id a
1 1
2
3
2 4
5
and
df4 = pd.Dataframe(
[
{'a': 6},
{'a': 7},
]
)
I want the concatenation to give
df_id a
1 1
2
3
2 4
5
3 6
7
Using the same function.
How can I achieve this correctly?
EDIT: A discount- I can manage with only the incrementing function. It doesn't have to work with the single level dfs, but it would be nice if it did.