简体   繁体   English

如果任何行值在另一个数据框中,则从数据框中删除一行,数据框具有多列

[英]remove a row from a dataframe if any row value is in another dataframe , with dataframes having multiple columns

I hava two data frames :我有两个数据框:

df1 = {0:[1,2,3,4,5,6,7,11],1:[100,20,7]}

df2 = {0:[100,4,6,7],1:[1,3,4,7]}

i have to remove rows from df1 that occurs in any row of df2我必须从 df1 中删除出现在 df2 的任何行中的行

result dataframe结果数据框

df3 = [2,5,11,20]

You can flatten values by np.ravel and get difference by np.setdiff1d :您可以通过扁平化值np.ravel并获得通过差异np.setdiff1d

df1 = pd.DataFrame({0:[1,2,3,4,5,6,7,11],1:[100,20,7,1,2,3,4,5]})
df2 = pd.DataFrame({0:[100,4,6,7],1:[1,3,4,7]})

L = np.setdiff1d(np.ravel(df1), np.ravel(df2)).tolist()
print (L)
[2, 5, 11, 20]

Or difference of sets:或集的差异:

L = list(set(df1.stack()) - set(df2.stack()))
print (L)
[2, 11, 20, 5]

暂无
暂无

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

相关问题 如果任何行值在另一个数据框中,则从数据框中删除一行 - remove a row from a dataframe if any row value is in another dataframe 如果多列包含特定值,则删除 pandas dataframe 中的一行 - Remove a row in pandas dataframe if multiple columns contains specific value 基于两列 A、B 从数据框中删除重复项,在另一列 C 中保留具有最大值的行 - Remove duplicates from dataframe, based on two columns A,B, keeping row with max value in another column C Python 从多个数据帧创建 dataframe,其中一个数据帧具有多个列 - Python create dataframe from multiple dataframes with one having multiple columns 根据来自另一个数据框的值将数据框拆分为多个数据框 - Splitting dataframe into multiple dataframes based on value from another dataframe 有没有办法从另一个行长度不确定的数据帧动态生成数据帧? - Is there a way to dynamically generate dataframes from another dataframe of indefinite row length? 如果列值从数据框中删除行 - Remove row from dataframe if column value 根据 Python 中另一个 dataframe 的行值从 dataframe 中获取列? - Taking columns from a dataframe based on row values of another dataframe in Python? 将一行从 dataframe 插入到另一个 dataframe 列重叠的地方 - Inserting a row from dataframe to another dataframe where columns overlap 从分组列中另一个 DataFrame 的每一行创建 DataFrame? - create DataFrame from each row of another DataFrame in grouped columns?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM