*chevron_left*Series Cookbook

Appending values to a SeriesApplying a function to SeriesBinning values in a SeriesChanging data type of SeriesChecking if a value is NaN in Pandas SeriesChecking if all values are NaN in SeriesChecking if all values in a Series are uniqueChecking if Series has missing valuesConverting Python list to SeriesConverting Series of lists into DataFrameConverting Series to a Numpy arrayConverting Series to Python listCounting frequency of values in SeriesCreating a Series of zeroesCreating a Series with constant valueFiltering strings based on length in SeriesFiltering values of a SeriesGetting frequency counts of values in intervalsGetting index of largest valueGetting index of smallest valueGetting index of value in SeriesGetting integer index of largest valueGetting integer index of smallest valueGetting integer index of value in SeriesGetting intersection of SeriesGetting length of each string in SeriesGetting list of integer indices where value is boolean True in SeriesGetting the index of the nth value in SeriesGetting the most frequent value in SeriesGetting value of Series using integer indexGrouping Series by its valuesHandling error - "Truth value of a Series is ambiguous"Inverting a Series of booleansRemoving missing values from a SeriesRemoving substrings from strings in a SeriesRemoving values from SeriesResetting index of SeriesSorting values in a SeriesSplitting strings based on spaceStripping leading and trailing whitespaceTaking the floor or ceiling of values in SeriesUsing index.get_loc(~) for multiple values

0

0

0

new

# Getting list of integer indices where value is boolean True in Pandas Series

Programming

*chevron_right*

Python

*chevron_right*

Pandas

*chevron_right*

Cookbooks

*chevron_right*

Series Cookbook

*schedule*Mar 9, 2022

Python●Pandas

Tags *toc*Table of Contents

*expand_more*

To get a list of integer indices where value is `True`

in a Pandas Series, use NumPy's `where(~)`

method:

```
s = pd.Series([False, True, False, True])np.where(s)[0]
array([1, 3])
```

`where(~)`

returns a tuple of size one, so we are using `[0]`

to fetch the array.

If you wanted a Python list instead, simply perform casting via `list(~)`

:

```
s = pd.Series([False, True, False, True])list(np.where(s)[0])
[1, 3]
```

Published by Isshin Inada

Edited by 0 others

Did you find this page useful?

Ask a question or leave a feedback...