-1

I have an output like this:

Vanuatu                                22        10
Venezuela(Bolivarian Republic of)      32        10
Viet Nam                               44        05

and I want something like this:

Vanuatu                                22        10
Venezuela                              32        10
Viet Nam                               44        05

Imagine that I have a Data Frame too long, like 500 Indexes. How can I do to remove it from all in my DF?

MACL mil
  • 1
  • 1

2 Answers2

0

I think, this is exactly what you are looking for:

import re
df['column_name'] = df['column_name'].str.replace(r'\([^)]*\)', '')
Vishal Upadhyay
  • 781
  • 1
  • 5
  • 19
0

Data

data = pd.DataFrame({'Name':['Vanuatu', 'Venezuela(Bolivarian Republic of)','Viet Nam' ]})

Use regex expression to call and replace anything between the parenthesis and the parenthesis themselves

df['Name']=df.Name.str.replace('\(+[A-Za-z|\s+\)]+','')
df

Explanation \( -special character (

+ match anything to the left

A-Za-z match any upper or lower case letters

| or

\s white space

+ match anything to the left

\) special character )

combined [A-Za-z|\s+\)]+ match any upper and lower cases or white spaces to the left

enter image description here

wwnde
  • 26,119
  • 6
  • 18
  • 32