Skip to content

Commit 6a1cbd3

Browse files
TomAugspurgerPingviinituutti
authored andcommitted
Update DataFrame.eq docstring (pandas-dev#24774)
1 parent 8423485 commit 6a1cbd3

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

pandas/core/ops.py

+30-24
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,7 @@ def _get_op_name(op, special):
732732
B 150 250
733733
C 100 300
734734
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:
737736
738737
>>> df == 100
739738
cost revenue
@@ -747,33 +746,40 @@ def _get_op_name(op, special):
747746
B False False
748747
C True False
749748
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:
753751
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:
759759
760-
>>> df.ne([100, 250, 300], axis='index')
760+
>>> df.ne(pd.Series([100, 300], index=["A", "D"]), axis='index')
761761
cost revenue
762762
A True False
763-
B True False
764-
C True False
763+
B True True
764+
C True True
765+
D True True
765766
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`:
771769
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
777783
778784
Compare to a DataFrame of different shape.
779785
@@ -798,7 +804,7 @@ def _get_op_name(op, special):
798804
>>> df_multindex = pd.DataFrame({{'cost': [250, 150, 100, 150, 300, 220],
799805
... 'revenue': [100, 250, 300, 200, 175, 225]}},
800806
... index=[['Q1', 'Q1', 'Q1', 'Q2', 'Q2', 'Q2'],
801-
... ['A', 'B', 'C', 'A', 'B' ,'C']])
807+
... ['A', 'B', 'C', 'A', 'B', 'C']])
802808
>>> df_multindex
803809
cost revenue
804810
Q1 A 250 100

0 commit comments

Comments
 (0)