Issue
I have dataframe with column 'code':
How can I drop repeated character '|' and leave only one.
I do:
df['code'] = df['code'].str.replace('|(?=|\1+)', '', regex=True)
or
df['code'] = df['code'].str.replace('|(?=|)', '', regex=True)
But repeated character does not drop.
Solution
Try this:
df["code"] = df["code"].str.replace(r'\|+', '|')
Answered By - Talha Khan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.