1

Given this

import pandas as pd

data = pd.Series([True, True, False, False],
    index=['2019-01-01','2019-01-02','2019-01-03','2019-01-04'])

data[data]     # why this works?
data[-data]

Is there any other way besides the above.

Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48
Jason
  • 81
  • 6
  • Does this answer your question? [Getting a list of indices where pandas boolean series is True](https://stackoverflow.com/questions/52173161/getting-a-list-of-indices-where-pandas-boolean-series-is-true) – LoukasPap Feb 03 '21 at 16:15
  • Search for boolean indexing: on the [documentation](https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#why-does-assignment-fail-when-using-chained-indexing). – Quang Hoang Feb 03 '21 at 16:15
  • Is your question another way to return where the series is True (i.e another way to do the same thing as `data[data]`)? Or are you wanting to know how to return a series where the value is False (I am assuming `data[-data]` is your attempt at this)? – dshanahan Feb 03 '21 at 16:18
  • I'm missing something here. I can understand data[0], and I can understand something like linq where data.where(values == false). But why data[data] can return all record with true values. You mentioned because it is a Boolean index, I thought the index is actually the date string. Just trying to get my head around it. – Jason Feb 04 '21 at 21:34

0 Answers0