Skip to content

Commit 75e2ee4

Browse files
committed
DOC: Improve docs (GH19312) for Series.nonzero()
1 parent 1c0a48c commit 75e2ee4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pandas/core/series.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def compress(self, condition, *args, **kwargs):
490490

491491
def nonzero(self):
492492
"""
493-
Return the indices of the elements that are non-zero
493+
Return the *integer* indices of the elements that are non-zero
494494
495495
This method is equivalent to calling `numpy.nonzero` on the
496496
series data. For compatibility with NumPy, the return value is
@@ -508,6 +508,15 @@ def nonzero(self):
508508
3 4
509509
dtype: int64
510510
511+
>>> s = pd.Series([0, 3, 0, 4], index=['a', 'b', 'c', 'd'])
512+
# same return although index of s is different
513+
>>> s.nonzero()
514+
(array([1, 3]),)
515+
>>> s.iloc[s.nonzero()[0]]
516+
b 3
517+
d 4
518+
dtype: int64
519+
511520
See Also
512521
--------
513522
numpy.nonzero

0 commit comments

Comments
 (0)