I need to remove some words into a cell of a dataframe with a condition until a ","

Question:

I have one data set in the column "Tags" I would like to remove in each cell from the world "importacion" to the "," and in some cases, it is just alone without the ",":

"importacion-2022-04-20-10:35:20, curioso, new user,lead_player,female,view_snapshot_cinnabon,like_cinnabon,view_legals_cinnabon,view_snapshot_moneypool,view_snapshot_la borra del café,view_snapshot_galt energy,like_la borra del café,view_snapshot_mccarthy's irish pub,like_mccarthy's irish pub,view_snapshot_la cervecerÃxada de barrio,like_la cervecerÃxada de barrio"

df["Tags"]=df.Tags.apply(lambda x: x.split(',') x[0].replace('') if x=='importacion' else pass )

obviously its not working.

enter image description here

enter image description here

Answers:

You might be able to just use str.replace here:

df["Tags"] = df["Tags"].str.replace(r'^importacion.*,s*', '', regex=True)
Answered By: Tim Biegeleisen
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.