Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 313 characters in body
Source Link
EdChum
  • 396.6k
  • 204
  • 836
  • 583

The problem here is that it's interpreting the index as column values to perform the comparison, if you use .gt and pass axis=0 then you get the result you desire:

In [203]: x.gt(x.mean(axis=1), axis=0) Out[203]: a b 0 False True 1 False True 

You can see what I mean when you perform the comparison with the np array:

In [205]: x > x.mean(axis=1).values Out[205]: a b 0 False False 1 False True 

here you can see that the default axis for comparison is on the column, resulting in a different result

The problem here is that it's interpreting the index as column values to perform the comparison, if you use .gt and pass axis=0 then you get the result you desire:

In [203]: x.gt(x.mean(axis=1), axis=0) Out[203]: a b 0 False True 1 False True 

The problem here is that it's interpreting the index as column values to perform the comparison, if you use .gt and pass axis=0 then you get the result you desire:

In [203]: x.gt(x.mean(axis=1), axis=0) Out[203]: a b 0 False True 1 False True 

You can see what I mean when you perform the comparison with the np array:

In [205]: x > x.mean(axis=1).values Out[205]: a b 0 False False 1 False True 

here you can see that the default axis for comparison is on the column, resulting in a different result

Source Link
EdChum
  • 396.6k
  • 204
  • 836
  • 583

The problem here is that it's interpreting the index as column values to perform the comparison, if you use .gt and pass axis=0 then you get the result you desire:

In [203]: x.gt(x.mean(axis=1), axis=0) Out[203]: a b 0 False True 1 False True