Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGaurav Sharma
5,496 PointsFind all of the columns in the demographics file that contain string data.
Can someone help me with this, I really can not find a way to solve this question :
how to set condition to find all values that holds string value, i tried below two codes that have failed:
demo.loc[demo["astype"]=="str"] demo.loc[demo.astype=="str"]
1 Answer
Brian Heneghan
4,115 PointsSo from what I gather, Pandas refers to 'string' as 'object'. So a little tweak to your code, first to save the results that are referring to if the columns are 'object' and then another to only view which columns are 'True'.
typeCol=(demo.dtypes==object)
typeCol.loc[typeCol==True]