学生有两个数据帧。“费用”数据框中缺少部分学生的费用明细。我想返回所有学生的详细资料,谁的费用细节丢失。“Class”、“Section”和“RollNo”三个字段构成了一个唯一的组合。在
Students = pd.DataFrame({
'Class': [7, 7, 8],
'Section': ['A', 'B', 'B'],
'RollNo': [2, 3, 4],
'Student': ['Ram', 'Rahim', 'Robert']
})
Fee = pd.DataFrame({
'Class': [7, 7, 8],
'Section': ['A', 'B', 'B'],
'RollNo': [2, 2, 3],
'Fee': [10, 20, 30]
})
Fee
Class Fee RollNo Section
0 7 10 2 A
1 7 20 2 B
2 8 30 3 B
基本上,我希望在基于上述3个字段的“Students”和“Fee”数据帧之间执行左联接时,从左表中查找不匹配的记录。使用Python中的Pandas实现这一点的最简单方法是什么?在
非常感谢!在
如果在} anf filter by ^{} 和{a3}:
Fee
数据帧的Fee
列中没有NaN
,请使用^{使用
^{pr2}$NaN
s的更一般的解决方案还将参数indicator
添加到merge
并使用left_only
过滤行:我对这个概念很感兴趣。在
选项1
pandas.concat
与keys
参数一起使用Students
s部分的结果MultiIndex
的第一个级别的值为'stu'
。在pandas.DataFrame.drop_duplicates
与参数keep=False
一起使用可删除所有重复。在loc
,将注意力集中在{方案2
使用元组列表上的集合,取一个差异并与一个人工数据帧合并。在
^{pr2}$相关问题 更多 >
编程相关推荐