First is necessary same index and same columns names in both DataFrame
s.
Then use DataFrame.where
for set missing values to False values by mask and then get mean
:
df = df1.where(df2 >= 0.5).mean()
If need mean of all values use numpy.nanmean for exclude missing values:
mean = np.nanmean(df1.where(df2 >= 0.5))
Another idea is convert all values to Series
with DataFrame.stack
and then get mean:
mean = df1.where(df2 >= 0.5).stack().mean()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…