I have a set of DataFrames with numeric values and partly overlapping indices. I would like to merge them an take the mean if an index occurs in more than one DataFrame.
import pandas as pd
import numpy as np
df1 = pd.DataFrame([1,2,3], columns=['col'], index=['a','b','c'])
df2 = pd.DataFrame([4,5,6], columns=['col'], index=['b','c','d'])
This gives me two DataFrames:
col col
a 1 b 4
b 2 c 5
c 3 d 6
Now I would like to merge the DataFrames and take the mean for each index (if applicable, i.e. if it occurs more than once).
Should look like this:
col
a 1
b 3
c 4
d 6
Can I do this with some advanced merging/joining?