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

How to split series of string by multi symbol?

At first, I have to write function GetTitle() method, where takes string, and this function must split the name till comma, then again split till dot, next convert the title to lower case and finally return this value of the title.

I wrote function, but I don’t get how to use or rewrite this function for series of string

def GetTitle(Name):
    k=Name.split(" ")
    item=k[1]
    title=item.split(".")
    res=title[0]
    lower_res=res.lower()
    return lower_res

This my column, where I should use this function

Photo

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

>Solution :

Assuming you wish to run your defined function on column "Name" & your data is loaded as df… Try this then;

df["Title"] = df["Name"].apply(lambda x: GetTitle(str(x)))
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