I have a DataFrame df1
(index as a datetime) and df2
with many columns,different length index.
I need to combine df1
with df2
, replacing index in df2
. As a result presented df3
.
df1
T1
2011-09-01 00:00:00 10
2011-09-01 00:10:00 20
2011-09-01 00:20:00 30
2011-09-01 00:30:00 40
df2
T2 T3
0 1.1 2.0
1 1.2 3.0
2 1.3 4.0
df3
T1 T2 T3
2011-09-01 00:00:00 10 1.1 2.0
2011-09-01 00:10:00 20 1.2 3.0
2011-09-01 00:20:00 30 1.3 4.0
2011-09-01 00:30:00 40 Nan Nan
I wanted to try concat, join, merge, append
but those doesn't seem to be appropriate.
Using set_index
resulted in having an error: length mismatch.
I end up trying this:
df3=pd.DataFrame(df2,index=df1.index,copy=True)
I got the desired index, and columns from df2
but they were empty.