diff --git a/pandas/core/series.py b/pandas/core/series.py index be40f65186d2d..fc512d23a05ba 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -490,7 +490,7 @@ def compress(self, condition, *args, **kwargs): def nonzero(self): """ - Return the indices of the elements that are non-zero + Return the *integer* indices of the elements that are non-zero This method is equivalent to calling `numpy.nonzero` on the series data. For compatibility with NumPy, the return value is @@ -508,6 +508,15 @@ def nonzero(self): 3 4 dtype: int64 + >>> s = pd.Series([0, 3, 0, 4], index=['a', 'b', 'c', 'd']) + # same return although index of s is different + >>> s.nonzero() + (array([1, 3]),) + >>> s.iloc[s.nonzero()[0]] + b 3 + d 4 + dtype: int64 + See Also -------- numpy.nonzero