TransWikia.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!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP