Is they a way to remove the incomplete parenthesis and parenthesis that contains 4 characters or above using Pandas, Python?

Viewed 28

I have a data frame where I want to remove the parentheses and characters inside it if there are 4 characters and above.

Assume the following dataframe "cusomter" with the column "Name"

Name
Company ABC (M) Ltd
Company EFG (M) Ltd (B123)
Company HIJ (M) Ltd (B12
Company KLM (M) Ltd (

I got my code by referring How to remove parentheses and all data within using Pandas/Python?

customer["Name"] = customer["Name"].str.replace(r"\([^()]*\)", "", regex=True)

Output

Name
Company ABC Ltd
Company EFG Ltd

The output I'm expecting

Name
Company ABC (M) Ltd
Company EFG (M) Ltd
Company HIJ (M) Ltd
Company KLM (M) Ltd

Is there a possible way to do it?

Thank you in advance

0 Answers
Related