1

i need to replace any after "(" in pandas dataframe by ""

Tuscaloosa (University of Alabama >> Tuscaloosa and 

df['RegionName']= df['RegionName'].str.replace(r"\s+\(.*\"","")

not work

2 Answers 2

1

You can using str.split

s
Out[417]: 
0    Tuscaloosa (University of Alabama >> Tuscaloosa
0    Tuscaloosa (University of Alabama >> Tuscaloosa
0    Tuscaloosa (University of Alabama >> Tuscaloosa
0    Tuscaloosa (University of Alabama >> Tuscaloosa
dtype: object
s.str.split('(',1).str[0]
Out[418]: 
0    Tuscaloosa 
0    Tuscaloosa 
0    Tuscaloosa 
0    Tuscaloosa 
dtype: object
Sign up to request clarification or add additional context in comments.

Comments

1

You can use str.extract (Using data from @Wen):

s.str.extract(r'([^(]+)')

0  Tuscaloosa
1  Tuscaloosa
2  Tuscaloosa
3  Tuscaloosa

1 Comment

Thnx alot it's work but i need to know the meaning of that and what is '([^(]+)' means

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.