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.

['IMI', ‘50’]

Out put Should be like this

I used this method but not working

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

>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

Leave a ReplyCancel reply