Binary operators between DataFrame and Series object doesn't seem to work · Issue #5284 · pandas-dev/pandas (original) (raw)
related similar operation
http://stackoverflow.com/q/21627926/190597
This should be a bit more intuitive
In [59]: data = """ A B C D
1/1 0 1 0 1
1/2 2 1 1 1
1/3 3 0 1 0
1/4 1 0 1 2
1/5 1 0 1 1
1/6 2 0 2 1
1/7 3 5 2 3"""
In [60]: df = read_csv(StringIO(data),sep='\s+')
In [61]: df
Out[61]:
A B C D
1/1 0 1 0 1
1/2 2 1 1 1
1/3 3 0 1 0
1/4 1 0 1 2
1/5 1 0 1 1
1/6 2 0 2 1
1/7 3 5 2 3
In [62]: df.where((df>df.shift(1)).values & DataFrame(df.D==1).values)
Out[62]:
A B C D
1/1 NaN NaN NaN NaN
1/2 2 NaN 1 NaN
1/3 NaN NaN NaN NaN
1/4 NaN NaN NaN NaN
1/5 NaN NaN NaN NaN
1/6 2 NaN 2 NaN
1/7 NaN NaN NaN NaN
Given that normal binary operators like addition or logical and
work well between a pair of Series objects, or between a pair of DataFrame objects (returning a element-wise addition/conjuction), I found it surprising that I cannot do the same between a Series object and a DataFrame object.
Here's a demonstration of what doesn't work now and what would be the expected result: http://nbviewer.ipython.org/urls/dl.dropboxusercontent.com/u/52886258/000-qdoqud/Untitled0.ipynb