In pandas
, you can do this:
>>> x = pd.DataFrame([[1,2,3,4], [3,4,5,6]], columns=list('abcd'))
>>> x
a b c d
0 1 2 3 4
1 3 4 5 6
>>> 2 < x.a
0 False
1 True
Name: a, dtype: bool
However, when I try it with it with a numpy
float:
>>> np.float64(2) < x.a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/simon/Documents/workspace/rent-my-rez/venv/lib/python2.7/site-packages/pandas/core/ops.py", line 741, in wrapper
if len(self) != len(other):
TypeError: len() of unsized object
Is there some way around this (which doesn't involve casting the numpy
float to a regular float), or some way I can monkey patch the Series
class from pandas to implement reverse comparison? I've looked around in the source code for where comparison is implemented, but I couldn't find it, so a reference to the location in the code would be very helpful
(I am aware that it is easily fixed by changing the order of comparison, but I am asking this more out of interest, as I would like to understand the source code more)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments