'Pandas matching and replace value with regex
I'm triyng to use df.Content.replace(r'^Quote.*\n+$', '', regex=True, inplace=True) to match and replace the first part ot the string, starting with "Quote" and to end with new line, excluding all " text" and keeping the only "Another text". Nevertheless, it only removes "Quote from Atsi on 09 2 2020, 15:13", but not "text"
Quote from Atsi on 09 2 2020, 15:13
Text Text Text Text Text
Text Text Text Text Text Text
Text Text Text Text Text
Another text Another text Another text Another text Another text
Solution 1:[1]
Please try the re module.
import re
df.Content.apply(lambda x:re.sub(r"Quote.*\n+", '', x, flags=re.DOTALL))
Explain
The flags=re.DOTALL means make dot match newline, which makes the \n+ work
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 | FavorMylikes |
