This is my original DataFrame (with multiindex column):
In [72]:df
Out[72]:
a b
x y x y
0 1.545293 -0.459270 0.899254 -1.010453
1 0.458760 0.275400 -0.190951 0.169195
2 -0.941817 1.109823 0.077953 -0.247074
3 1.790101 -1.643470 0.979625 -1.704657
4 -2.044814 -0.243726 -0.039724 0.600066
and I have another DataFrame:
In [77]:df2
Out[77]:
x y
0 -1.085869 -0.952949
1 0.601585 0.570050
2 0.328601 0.802610
3 -0.415952 -0.090088
4 0.757545 -0.736933
how can I add df2's columns to df to get a new DataFrame like this:
In [83]:df3
Out[83]:
a b c
x y x y x y
0 1.545293 -0.459270 0.899254 -1.010453 -1.085869 -0.952949
1 0.458760 0.275400 -0.190951 0.169195 0.601585 0.570050
2 -0.941817 1.109823 0.077953 -0.247074 0.328601 0.802610
3 1.790101 -1.643470 0.979625 -1.704657 -0.415952 -0.090088
4 -2.044814 -0.243726 -0.039724 0.600066 0.757545 -0.736933
My current approach is to use a for loop:
for col in df2.columns:
df['c', col] = df2[col]
is there any method to avoid the loop?