说:
df1
IMG | isHotDogConfidence
img1 | 0
img2 | 1
img3 | 0
img4 | 0
img5 | 1
df2
IMG | isHotDogConfidence
img1 | 1
img2 | 1
img3 | 1
img4 | 0
img5 | 0
我想要什么:
IMG | isHotDogConfidence
img1 | 0.5
img2 | 1
img3 | 0.5
img4 | 0
img5 | 0.5
您将如何使用熊猫有效地做到这一点?
答案 0 :(得分:1)
将concat
与汇总mean
一起使用:
df = pd.concat([df1, df2]).groupby('IMG', as_index=False).mean()
print (df)
IMG isHotDogConfidence
0 img1 0.5
1 img2 1.0
2 img3 0.5
3 img4 0.0
4 img5 0.5