-2

I've got a Dataframe containing strings like this

A header Another header
First row
Second row
[First] nenen row
[Second] mmm row

I want to remove all the text in brackets ([xxx]) and keep the rest of the string in each row.

How can I do that?

  • Does this answer your question? [How to remove parentheses and all data within using Pandas/Python?](https://stackoverflow.com/questions/20894525/how-to-remove-parentheses-and-all-data-within-using-pandas-python) – Alex Sep 09 '21 at 14:44
  • See [this answer](https://stackoverflow.com/a/56701635/3279716) for a look at the difference between the regex in the answers here. – Alex Sep 09 '21 at 14:47

1 Answers1

0
>>> df
         a header another header
0           first            row
1  [First] second            row
>>> df["a header"]=df["a header"].str.replace(r'\[.*?\]\ *','')
>>> df
  a header another header
0    first            row
1   second            row
Theofilos Papapanagiotou
  • 5,133
  • 1
  • 18
  • 24