简体   繁体   English

检查数据框中的值是否存在于每一行的另一列中

[英]Check if value in dataframe exists in another column for each row

Dataframe in question, df:有问题的数据框,df:

colA colB
1  [1, 4, 5]
4  [3, nan, nan]

I'm trying to return a Series which has True where colA's value is in colB's value for each row.我试图返回一个具有 True 的系列,其中 colA 的值在每一行的 colB 值中。

The result should be:结果应该是:

True
False

I tried: df.colA.isin(df.colB) - but that doesn't do the trick because colB's values are in lists我试过: df.colA.isin(df.colB) - 但这并不能解决问题,因为 colB 的值在列表中

您需要在isin之前解压列表列

m = pd.DataFrame(df['colB'].tolist(),index=df.index).isin(df['colA']).any(axis=1)

暂无
暂无

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

相关问题 检查 dataframe 中的行值是否存在于另一个 dataframe 中,使用循环进行协调 - Check if row value in a dataframe exists in another dataframe using loop for reconciliation 检查一个数据框中的值是否存在于另一个数据框中并创建列 - Check if value from one dataframe exists in another dataframe and create column 对于Pandas数据框中的每一行,确定另一列中是否存在一列值 - For every row in Pandas dataframe determine if a column value exists in another column 如何检查pandas数据帧中是否存在具有特定列值的行 - How to check if there exists a row with a certain column value in pandas dataframe 访问每一行并检查数据框中的每一列值 - Acces each row and check each column value in dataframe 用另一个列的每个值迭代数据框的一行的值 - iterate a value of a row of a dataframe with each value of a column in another 检查 dataframe 中的每一行和每一列,并用用户定义的 function 替换值 - check each row and column in dataframe and replace value with user define function 检查一个 dataframe 中的列对是否存在于另一个中? - Check if column pair in one dataframe exists in another? 检查每个列值是否存在于另一个 dataframe 列中,其中另一个列值是列 header - Check if each column values exist in another dataframe column where another column value is the column header 检查另一个数据框列中是否存在数据框列中的少数值 - To check if few values in dataframe column exists in another dataframe column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM