I am trying to work with Pandas on some data problems and have come to a point where I am writing code like this:
groups.segment = groups.topic.map(lambda x: 'friends' if 'friend' in str(x) else x)
groups.segment = groups.topic.map(lambda x: 'friends' if 'bro' in str(x) else x)
groups.segment = groups.topic.map(lambda x: 'friends' if 'girls' in str(x) else x)
I would like to write it in a more concise way way where I don't have to have a bunch of copy and paste code. A little bit new to python so not sure how to make it better. Any help appreciated.
Something along the lines of:
groups.segment = groups.segment.map(lambda x: 'friends' if 'bro' or 'girls' or 'friend' in str(x) else x)
Is there a way to do this ?
Thanks for any help !
anybuilt-in function.