简体   繁体   English

检查另一个数据框列中是否存在数据框列中的少数值

[英]To check if few values in dataframe column exists in another dataframe column

I am trying to check if values present in df1 column is present in df2 column.我正在尝试检查 df1 列中存在的值是否存在于 df2 列中。 df2 contains more values than df1 and cant use for loop df2 包含比 df1 更多的值并且不能使用for循环

import pandas as pd

df1 = pd.DataFrame({'one': [2,4,6,8]})
df2 = pd.DataFrame({'one': [4,2,6,8,10]})

print(df1.isin(df2))  

expected results预期成绩

    one
0  True
1  True
2   True
3   True

actual results实际结果

     one
0  False
1  False
2   True
3   True

2 and 4 are present in df2 , still due to order false is given. df2 中存在 2 和 4 ,仍然是由于给出了 false 的命令。 is there a way where order of values don't impact有没有一种方法可以不影响值的顺序

You can compare columns:您可以比较列:

print(df1['one'].isin(df2['one']))  
0    True
1    True
2    True
3    True
Name: one, dtype: bool

Or convert values of DataFrame to 1d array and then list:或者将 DataFrame 的值转换为一维数组,然后列出:

print(df1.isin(df2.to_numpy().ravel().tolist()))  
    one
0  True
1  True
2  True
3  True

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

相关问题 检查 PySaprk 列值是否存在于另一个 dataframe 列值中 - Check if PySaprk column values exists in another dataframe column values 检查一列中的值是否存在于另一数据框中的多列中 - Check if values from one column, exists in multiple columns in another dataframe 检查一个 dataframe 中的列对是否存在于另一个中? - Check if column pair in one dataframe exists in another? 检查列值是否存在于不同的 dataframe - Check if column values exists in different dataframe 检查一个数据框中的值是否存在于另一个数据框中并创建列 - Check if value from one dataframe exists in another dataframe and create column 如何检查一个数据帧中的列值是否可用或不检查另一数据帧的列中的值? - How to check values of column in one dataframe available or not in column of another dataframe? pandas dataframe 检查列是否包含存在于另一列中的字符串 - pandas dataframe check if column contains string that exists in another column 如何检查数据框中的另一列中是否存在列的唯一值? - How do i check that the unique values of a column exists in another column in dataframe? 用另一个值替换熊猫数据框列中的几个值 - Replacing few values in a pandas dataframe column with another value 如果数据框存在于另一个数据框列中,则搜索它的子字符串 - Searching substring of a dataframe if it exists in another dataframe column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM