我有以下两个数据帧,它们的大小不同:df1(966行x 2列),df2(36行,2列),其中
df1:
Video_# Selected Joint.1
484 1 Left_shoulder
778 1 Left_shoulder
418 1 Right_shoulder
964 1 Right_shoulder
193 1 Right_shoulder
... ... ... ... ...
285 36 Right_elbow
267 36 Left_hand
216 36 Shoulder_centre
139 36 Right_shoulder
df2:
Video_# Ann.1
0 1 Shoulder_center
1 2 Head
2 3 Right_hip
... ... ... ... ...
33 34 Left_knee
34 35 Right_knee
35 36 Right_shoulder
哪里有Video_#
1-36。在df2
该Video_#
列中,每个元素仅出现一次,因此1-36仅出现一次。尽管df1
每个1-36中有多次出现,但每个1-36中的出现次数却不同(我希望这是有道理的)。
我要检查的是df1['Selected Joint.1'] == df2['Ann.1']
基于的出现次数Video_#
。因此,预期输出为(例如):
Video_# Equality Occurrences
1 3
2 5
... ... ...
36 6
那可能吗?
使用DataFrame.merge
有GroupBy.size
:
df = (df1.merge(df2,
left_on=['Video_#','Selected Joint.1'],
right_on=['Video_#','Ann.1'])
.groupby('Video_')
.size()
.reset_index(name='Equality Occurrences'))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句