我正在尝试使用 Numexpr 来制作过滤器。当我尝试运行下一个代码片段时:
>>> import pandas as pd
>>> import numexpr
>>> df=pd.DataFrame({'a':[1,2,3],'b':['one','two','three']})
>>> df
a b
0 1 one
1 2 two
2 3 three
>>> a=df.a.values
>>> b=df.b.values
>>> numexpr.evaluate('a<2')
array([ True, False, False])
>>> numexpr.evaluate('b=="one"')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python36-64\lib\site-packages\numexpr\necompiler.py", line 822, in evaluate
zip(names, arguments)]
File "C:\Python36-64\lib\site-packages\numexpr\necompiler.py", line 821, in <listcomp>
signature = [(name, getType(arg)) for (name, arg) in
File "C:\Python36-64\lib\site-packages\numexpr\necompiler.py", line 703, in getType
raise ValueError("unknown type %s" % a.dtype.name)
ValueError: unknown type object
出于某种原因,我不能使用 df.eval('b=="one"')。也许我做错了。任何帮助,将不胜感激。