concat_with_column_name¶
In [1]:
import pandas as pd
s1 = pd.Series(range(5), name="a")
s2 = pd.Series(range(1, 6), name="b")
s3 = pd.Series(range(2, 7))
s4 = pd.Series(range(3, 8))
pd.concat([
pd.concat(
[
pd.DataFrame(s1),
s2.to_frame()
], axis=1
),
pd.concat([s3, s4], keys=list("cd"), axis=1),
pd.DataFrame({"e": s3, "f": s4})
], axis=1).head()
Out[1]:
a | b | c | d | e | f | |
---|---|---|---|---|---|---|
0 | 0 | 1 | 2 | 3 | 2 | 3 |
1 | 1 | 2 | 3 | 4 | 3 | 4 |
2 | 2 | 3 | 4 | 5 | 4 | 5 |
3 | 3 | 4 | 5 | 6 | 5 | 6 |
4 | 4 | 5 | 6 | 7 | 6 | 7 |