Remove the ending of a column in pandas dataframe starting from a specific substring

Viewed 44

I have a dataframe df with only one column which have strings like: 005f12b33ac4bdb310d8e503a065ef10b28566ea#code_id#alarm|clock

I want to remove the ending of the string starting from #code_id# and want the string to look like 005f12b33ac4bdb310d8e503a065ef10b28566ea

How can I do it?

2 Answers

Try this :

df['Column_name']= df['Column_name'].astype(str).str.split('#').str[0] 

Use:

df['col'] = df['col'].str.extract('(.*)#code_id#')
Related