简体   繁体   English

两个数据帧的公共列中的值的交集--Pandas,Python3

[英]Intersection of values in a common column of two dataframes- Pandas, Python3

I have 2 dataframes; 我有2个数据帧; dataframe main and dataframe mini, with exactly the same headers but with different values in them however there is some overlap. dataframe main和dataframe mini,标题完全相同但值不同,但有一些重叠。 How would I get the duplicate values within a single column (eg Column 'Name'). 如何在单个列中获取重复值(例如,列'名称')。

Example: 例:

dataframe main 数据框主要

Name    size    length
foo      1         2
foo2     3         4
foo3     5         6  
foo4     7         8

dataframe mini 数据帧迷你

Name     size     length
foox      60       70
foo3       3        4
fooy      50       60
foo4      7        8

psuedo code: intersect(column='Name', of='dataframe mini', against='dataframe main') 伪代码: intersect(column='Name', of='dataframe mini', against='dataframe main')

proposed out : (foo3,foo4) 建议: (foo3,foo4)

You can use isin to mask the row values that are in another df: 您可以使用isin来屏蔽另一个df中的行值:

In [52]:
main.loc[main['Name'].isin(mini['Name']), 'Name']

Out[52]:
2    foo3
3    foo4
Name: Name, dtype: object

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据两个不同数据帧中的重复键合并数据帧 - merging dataframes based on repeating keys in two different dataframes- pandas 在两个 Pandas 数据帧中查找公共行(交集) - Finding common rows (intersection) in two Pandas dataframes Pandas Dataframes-基于列标题添加字段 - Pandas Dataframes- Adding Fields Based on Column Titles Python pandas:按日期索引和公共列值组合两个数据帧 - Python pandas: Combine two dataframes by date index and a common column value 比较 Pandas 数据帧的布尔值 - 返回字符串 - Comparing Boolean Values of Pandas Dataframes- Returning String 在python中使用公共列和字符串条件合并两个熊猫数据帧 - Merge two pandas dataframes in python with a common column and with condition on string 使用 pandas python 基于公共值合并两个数据帧? - Merging two dataframes based on common values using pandas python? 按索引合并两个 pandas 数据帧并替换 Python 中的列值 - Merge two pandas dataframes by index and replace column values in Python 如何基于一个公共列但不同的内容合并/扩展两个 python pandas 数据帧? - How do I merge/expand two python pandas dataframes, based on one common column but different content? Python Pandas:使用公共列将3个具有字符串,数字和NaN值的数据框分组为一个新的数据框 - Python Pandas: groupby 3 dataframes with string, numeric and NaN values to a new dataframe using a common column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM