Pandas merge two dataframes by taking the mean between the columns

Viewed 1288

I am working with Pandas DataFrames and looking to take the mean between two of them. I am looking to take the mean between columns with the same names. For example

df1

    time     x    y     z
 0     1  1.25  2.5  0.75
 1     2  2.75  2.5  3.00
 2     3  1.50  2.5  1.25
 3     4  3.00  2.5  3.50
 4     5  0.50  2.5  2.25

df2

    time     x    y     z
 0     2  0.75  2.5  1.75
 1     3  3.00  2.5  3.00
 2     4  1.25  2.5  0.25
 3     5  3.50  2.5  2.00
 4     6  2.25  2.5  2.25

and the result I am looking for is

df3

    time     x    y     z
 0     1  1.25  2.5  0.75
 1     2  1.75  2.5  2.375
 2     3  2.25  2.5  2.125
 3     4  2.125 2.5  1.875
 4     5  2.00  2.5  2.125
 5     6  2.25  2.5  2.25

Is there a simple way in Pandas that I can do this, using the merge function or similar? I am looking for a way of doing it without having to specify the name of the columns.

1 Answers
Related