我有数据 df 看起来像
Label1 Label2
a {l1,l2}
b {l1}
c {}
d {l3}
e {l3,l2}
我希望能够选择 Label2 列包含 l2 的行,即 label1 =a 和 e 的行。我知道 isin 方法,例如 df['Label2'].isin(..),但这不是同一种成员资格问题(更像是逆)。我想要一些看起来像 df['Label2'].contains('l2') 的东西。
请您参考如下方法:
如果您有一系列集合,只需使用intersection 运算符&
df.loc[df['Label2'] & {'l2'}]
