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

Unwanted String remove from string

I greatly appreciate your effort in trying to work out the formula to delete bracket and apostrophe but so far it hasn’t quite worked.

Data
['IMI', ‘50’]

Out put Should be like this
IMI,50

I used this method but not working

dataFrame['group_code'] = dataFrame['groups'].apply(lambda x: ', '.join([s[1:-1] for s in x]))

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 :

If the column contains strings, you should use .str.replace() to remove the characters you don’t want:

dataframe['groups'].str.replace(r"[\[\]']", "", regex=True)

If the column contains lists, don’t slice it, since the brackets aren’t list elements.

dataframe['groups'].apply(lambda l: ','.join(l))

See Pandas Column join list values

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