因为dataframe.str.*
函数仅用于字符串数据。由于您的数据不是字符串,因此无论字符串表示形式如何,它始终为NaN。证明:
>>> x = pd.DataFrame(np.random.randn(2, 5)).astype("object")
>>> x
0 1 2 3 4
0 -1.17191 -1.92926 -0.831576 -0.0814279 0.099612
1 -1.55183 -0.494855 1.14398 -1.72675 -0.0390948
>>> x[0].str.contains("-1")
0 NaN
1 NaN
Name: 0, dtype: float64
你能做什么:
用途apply
:
>>> x[0].apply(lambda x: "-1" in str(x))
0 True
1 True
Name: 0, dtype: bool
所以你的代码应该写:
print(rules[rules["antecedents"].apply(lambda x: 'line' in str(x))])
'line' in x
如果您是指元素完全匹配,则可能需要使用
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句