I am trying to merge these two dataframe together and preserve all the rows and columns. They have different times under the column 'time', so i want them to merge in a way that is time sequential.
df1:
time | run_id | weight |
---|---|---|
0 | H1 | 500 |
24 | H1 | 400 |
48 | H1 | 300 |
0 | H2 | 900 |
24 | H2 | 800 |
48 | H2 | 700 |
df2:
time | run_id | totalizer |
---|---|---|
0.5 | H1 | 100 |
10 | H1 | 200 |
40 | H1 | 300 |
60 | H1 | 400 |
0.5 | H2 | 900 |
5 | H2 | 1000 |
35 | H2 | 1100 |
70 | H2 | 1200 |
How do I merge these two tables into:
time | run_id | weight | totalizer |
---|---|---|---|
0 | H1 | 500 | |
0.5 | H1 | 100 | |
10 | H1 | 200 | |
24 | H1 | 400 | |
40 | H1 | 300 | |
48 | H1 | 300 | |
60 | H1 | 400 | |
0 | H2 | 900 | |
0.5 | H2 | 900 | |
5 | H2 | 1000 | |
24 | H2 | 800 | |
35 | H2 | 1100 | |
48 | H2 | 700 | |
70 | H2 | 1200 |
I tried:
mergedf = df1.merge(df2, how='outer')
but it stacked df1 on top of df2.