Comparing pandas DataFrame to Series

I looked through this and this question so far, but they really have not helped me with my problem.

The problem is very simple, but a bit complicated for words.

I have a Dataframe that has a matrix like:

       Stock1 Stock2
Date1   3      4
Date2   1      4

For each date that is my index, I want to compare the values ​​with one point in the Series.

Be like:

      Value
Date1   2
Date2   3

I want to build the next DataFrame from a comparison, e.g. DataFrame> Series

       Stock1 Stock2
Date1   True   True
Date2   False  True

So, for Date1both, the values ​​are greater than 2, and for Date2only Stock2greater than 3.

Thanks in advance

+4
source share
1 answer

.gt axis=0, :

In [126]:
df.gt(s, axis=0)

Out[126]:
      Stock1 Stock2
index              
Date1   True   True
Date2  False   True
+4

All Articles