Home > Blockchain >  Change pandas output to a list
Change pandas output to a list

Time:11-07

I have the following code:

omgangar = (matcher[
(matcher['rank'] >= 1) & 
(matcher['rank'] <= 1) & 
(matcher['odds'] >= oddsrank1) & 
(matcher['odds'] <= oddsrank1)]
['omg'].value_counts() == 1)

which returns following output:

3296    False
3985    False
2937     True
2984     True
3231     True
Name: omg, dtype: bool

Desired output is to only receive the omg which has True bool to a list: [2937, 2984, 3231]

I've tried some code but it only throws error. Any advice?

CodePudding user response:

IIUC, If you have this:

>>> omgangar = [3296, 3985, 2937, 2984, 3231]
>>> omgangar = pd.Series([False, False, True, True, True], index=omgangar) 
>>> omgangar
3296    False
3985    False
2937     True
2984     True
3231     True
dtype: bool

You can try this:

>>> omgangar[omgangar].index.tolist()
[2937, 2984, 3231]
  • Related