Home > Software design >  Remove the ending of a column in pandas dataframe starting from a specific substring
Remove the ending of a column in pandas dataframe starting from a specific substring

Time:02-01

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?

CodePudding user response:

Try this :

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

CodePudding user response:

Use:

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