Skip to content

Commit 9872d67

Browse files
droratajreback
authored andcommitted
DOC: Improve docs (GH19312) for Series.nonzero() (#19324)
1 parent d409eaf commit 9872d67

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
@@ -481,7 +481,7 @@ def compress(self, condition, *args, **kwargs):
481481

482482
def nonzero(self):
483483
"""
484-
Return the indices of the elements that are non-zero
484+
Return the *integer* indices of the elements that are non-zero
485485
486486
This method is equivalent to calling `numpy.nonzero` on the
487487
series data. For compatibility with NumPy, the return value is
@@ -499,6 +499,15 @@ def nonzero(self):
499499
3 4
500500
dtype: int64
501501
502+
>>> s = pd.Series([0, 3, 0, 4], index=['a', 'b', 'c', 'd'])
503+
# same return although index of s is different
504+
>>> s.nonzero()
505+
(array([1, 3]),)
506+
>>> s.iloc[s.nonzero()[0]]
507+
b 3
508+
d 4
509+
dtype: int64
510+
502511
See Also
503512
--------
504513
numpy.nonzero

0 commit comments

Comments
 (0)