@@ -732,8 +732,7 @@ def _get_op_name(op, special):
732
732
B 150 250
733
733
C 100 300
734
734
735
- Compare to a scalar and operator version which return the same
736
- results.
735
+ Comparison with a scalar, using either the operator or method:
737
736
738
737
>>> df == 100
739
738
cost revenue
@@ -747,33 +746,40 @@ def _get_op_name(op, special):
747
746
B False False
748
747
C True False
749
748
750
- Compare to a list and Series by axis and operator version. As shown,
751
- for list axis is by default 'index', but for Series axis is by
752
- default 'columns'.
749
+ When `other` is a :class:`Series`, the columns of a DataFrame are aligned
750
+ with the index of `other` and broadcast:
753
751
754
- >>> df != [100, 250, 300]
755
- cost revenue
756
- A True False
757
- B True False
758
- C True False
752
+ >>> df != pd.Series([100, 250], index=["cost", "revenue"])
753
+ cost revenue
754
+ A True True
755
+ B True False
756
+ C False True
757
+
758
+ Use the method to control the broadcast axis:
759
759
760
- >>> df.ne([100, 250, 300] , axis='index')
760
+ >>> df.ne(pd.Series( [100, 300], index=["A", "D"]) , axis='index')
761
761
cost revenue
762
762
A True False
763
- B True False
764
- C True False
763
+ B True True
764
+ C True True
765
+ D True True
765
766
766
- >>> df != pd.Series([100, 250, 300])
767
- cost revenue 0 1 2
768
- A True True True True True
769
- B True True True True True
770
- C True True True True True
767
+ When comparing to an arbitrary sequence, the number of columns must
768
+ match the number elements in `other`:
771
769
772
- >>> df.ne(pd.Series([100, 250, 300]), axis='columns')
773
- cost revenue 0 1 2
774
- A True True True True True
775
- B True True True True True
776
- C True True True True True
770
+ >>> df == [250, 100]
771
+ cost revenue
772
+ A True True
773
+ B False False
774
+ C False False
775
+
776
+ Use the method to control the axis:
777
+
778
+ >>> df.eq([250, 250, 100], axis='index')
779
+ cost revenue
780
+ A True False
781
+ B False True
782
+ C True False
777
783
778
784
Compare to a DataFrame of different shape.
779
785
@@ -798,7 +804,7 @@ def _get_op_name(op, special):
798
804
>>> df_multindex = pd.DataFrame({{'cost': [250, 150, 100, 150, 300, 220],
799
805
... 'revenue': [100, 250, 300, 200, 175, 225]}},
800
806
... index=[['Q1', 'Q1', 'Q1', 'Q2', 'Q2', 'Q2'],
801
- ... ['A', 'B', 'C', 'A', 'B' , 'C']])
807
+ ... ['A', 'B', 'C', 'A', 'B', 'C']])
802
808
>>> df_multindex
803
809
cost revenue
804
810
Q1 A 250 100
0 commit comments