AnswerBun.com

how to return only the True values?

Stack Overflow Asked by hnakashima96 on December 13, 2020

I’m checking if a word is in the object in a dataframe series. Like this:

indicators['Indicator Name'].str.contains('population')

But when I run this command, my result is all values as true or false.
How can I print only the true values and show all of them? Since the
dataframe is huge.Like this:

ndicator Code
EG.CFT.ACCS.ZS        True
EG.ELC.ACCS.ZS        True
EG.ELC.ACCS.RU.ZS     True
EG.ELC.ACCS.UR.ZS     True
FX.OWN.TOTL.ZS        True
                     ...  
SG.VAW.NEGL.ZS       False
SG.VAW.REFU.ZS       False
SP.M15.2024.FE.ZS    False
SP.M18.2024.FE.ZS    False
SH.DYN.AIDS.FE.ZS     True

2 Answers

Following on MhDG7 answer, you might as well use the boolean series as an indexer, like:

indicators[indicators['Indicator Name'].str.contains('population')]

Answered by Felipe Whitaker on December 13, 2020

Use lambda expresion:

indicators[lambda x: x['Indicator Name'].str.contains('population')]

Answered by Mehdi Golzadeh on December 13, 2020

Add your own answers!

Related Questions

Remove item from state

3  Asked on December 5, 2020 by clayton-crockville

 

How to concatenate 3 lists even if there are a list null?

2  Asked on December 5, 2020 by alexz

       

Angular 8: Select first element of ng-content

1  Asked on December 5, 2020 by ijustdev

     

docker-compose volume empty

3  Asked on December 5, 2020 by kerby82

   

Extract value of column from a line (variable)

4  Asked on December 4, 2020 by user4516211

       

Merge Two Files in Weka based on date

1  Asked on December 4, 2020 by spwath

 

Set Session ID Cookie in Nuxt Auth

1  Asked on December 4, 2020 by dominooch

   

Warnings in gcc compiler

1  Asked on December 3, 2020 by hygor-marques

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP