Python 从其他数据框中选择具有特定条件的行

Python 从其他数据框中选择具有特定条件的行,python,pandas,select,rows,Python,Pandas,Select,Rows,我有一个数据帧df,它有一列: colors red blue green black pink 还有另一个数据帧df1,它有许多列(~300列): 我需要的是返回df的行,它存在于df1.colorName中,并且在任何列(col1…colN)中至少有值1 那么从上面,;输出应为: blue pink 我从这里开始,但我确信它需要一个附加条件(检查任何列中至少有值1(col1…colN)) newDF=df[df.colors.isin(df1.colorName)&&] 如果我错了,请纠

我有一个数据帧
df
,它有一列:

colors
red
blue
green
black
pink
还有另一个数据帧df1,它有许多列(~300列):

我需要的是返回
df
的行,它存在于
df1.colorName
中,并且在任何列(col1…colN)中至少有值1

那么从上面,;输出应为:

blue
pink
我从这里开始,但我确信它需要一个附加条件(检查任何列中至少有值1(col1…colN))

newDF=df[df.colors.isin(df1.colorName)&&]

如果我错了,请纠正我的错误,如果有任何帮助,我们将不胜感激。

使用with select columns by-all columns with not first with for至少一行
True
,对于column
colorName
,请首先将其传递给筛选者:

详细信息

print (c)
0     pink
1    white
2     blue
Name: colorName, dtype: object
c = df1.loc[df1.iloc[:, 1:].any(axis=1), 'colorName']
#alternative
#c = df1.loc[df1.drop('colorName', axis=1).any(axis=1), 'colorName']
newDF = df[df. colors.isin(c)]
print (newDF)
  colors
1   blue
4   pink
print (c)
0     pink
1    white
2     blue
Name: colorName, dtype: object