'Remove the ending of a column in pandas dataframe starting from a specific substring
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?
Solution 1:[1]
Use:
df['col'] = df['col'].str.extract('(.*)#code_id#')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | keramat |
