Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change pandas output to a list

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]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Br,
OldSport

>Solution :

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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading