Using mutliple text formatting using lambda function in pandas dataframe in python? -
i trying format given string contains alphabets, special characters, , numbers. target remove except alphabets , space in string. able in multiple line of code not good. can me reformat blow line of codes can multiple formatting in online instead 4- lines below?
scholar['title_format'] = scholar['title'].map(lambda x: str(x)) #change value string scholar['title_format'] = scholar['title_format'].map(lambda x: re.sub(r'[^a-za-z ]', '', x)) #remove special characters scholar['title_format'] = scholar['title_format'].map(lambda x: re.sub(r'[0-9]', '', x)) #remove numbers scholar['title_format'] = scholar['title_format'].map(lambda x: x.lower()) #change lower case
iiuc:
scholar['title_format'] = scholar['title'].astype(str).str.lower() \ .str.replace(r'[^a-z\s]*', '')
update:
scholar['title_format'] = scholar['title'].astype(str).str.lower() \ .str.replace(r'[^a-z]*', '') \ .map(lambda x: ''.join(sorted(x)))
wiki
Comments
Post a Comment