如何使用Pandas Groupby过滤此数据框架?
使用python,您如何使用群组来过滤此数据
集启动
First Last Location ID1 ID2 First3 Last3
John Smith Toronto JohnToronto SmithToronto Joh Smi
Joh Smith Toronto JohToronto SmithToronto Joh Smi
Steph Sax Vancouver StephVancouver SaxVancouver Ste Sax
Steph Sa Vancouver StephVancouver SaxeVancouver Ste Sax
Stacy Lee Markham StacyMarkham LeeMarkham Sta Lee
Stac Lee Markham StacMarkham LeeMarkham Sta Lee
Stac Wong Aurora StacAurora LeeAurora Sta Won
Stac Lee Newmarket StacNewmarket LeeNewmarket Sta Lee
Steve Smith Toronto SteveToronto SmithToronto Ste Smi
John Jones Toronto JohnToronto JonesToronto Joh Jon
我该如何完成,以便在接受两个条件的地方,过滤所有不符合这两个条件
- ID1的所有其他条件 - 与另一个ID1匹配另一个ID1,而最后3则是相同的
- ID2-匹配另一个ID2,前3个是相同的
末端
First Last Location ID1 ID2 First3 Last3
John Smith Toronto JohnToronto SmithToronto Joh Smi
Joh Smith Toronto JohToronto SmithToronto Joh Smi
Steph Sax Vancouver StephVancouver SaxVancouver Ste Sax
Steph Sa Vancouver StephVancouver SaxeVancouver Ste Sax
Stacy Lee Markham StacyMarkham LeeMarkham Sta Lee
Stac Lee Markham StacMarkham LeeMarkham Sta Lee
Using Python how can you use a group-by to filter this dataset
Start
First Last Location ID1 ID2 First3 Last3
John Smith Toronto JohnToronto SmithToronto Joh Smi
Joh Smith Toronto JohToronto SmithToronto Joh Smi
Steph Sax Vancouver StephVancouver SaxVancouver Ste Sax
Steph Sa Vancouver StephVancouver SaxeVancouver Ste Sax
Stacy Lee Markham StacyMarkham LeeMarkham Sta Lee
Stac Lee Markham StacMarkham LeeMarkham Sta Lee
Stac Wong Aurora StacAurora LeeAurora Sta Won
Stac Lee Newmarket StacNewmarket LeeNewmarket Sta Lee
Steve Smith Toronto SteveToronto SmithToronto Ste Smi
John Jones Toronto JohnToronto JonesToronto Joh Jon
How can I make it so that where either the two conditions are accepted, filtering everything else that doesn't meet these two criteria
- ID1 - Matches another ID1 and the Last3 are the same
- ID2 - Matches another ID2 and the First 3 are the same
End
First Last Location ID1 ID2 First3 Last3
John Smith Toronto JohnToronto SmithToronto Joh Smi
Joh Smith Toronto JohToronto SmithToronto Joh Smi
Steph Sax Vancouver StephVancouver SaxVancouver Ste Sax
Steph Sa Vancouver StephVancouver SaxeVancouver Ste Sax
Stacy Lee Markham StacyMarkham LeeMarkham Sta Lee
Stac Lee Markham StacMarkham LeeMarkham Sta Lee
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用:
You may use:
根据澄清问题声明的评论 -
请尝试此方法 -
编辑:修改@Somedude提供的上述答案,您可以将其作为2个独立条件而无需组的情况和也要在它们之间进行或
Based on comment for clarification of the problem statement -
Try this approach -
EDIT: Modifying the above answer provided by @SomeDude, you can run this as 2 independent conditions without a groupby and take an OR between them as well -