0

This my pandas dataframe:

print(top)

Result:

Countries Population
China[B] 1376
India 1200

I want to remove the '[B]' from China, and for that, I ran the following code:

top['Countries'] = top['Countries'].str.replace('[B]', '')

But the result was unsatasfying:

Countries Population
China[] 1376
India 1200

I also received the following warning:

C:\Users\walde\AppData\Local\Temp/ipykernel_8068/4262663465.py:1: FutureWarning: The default value of regex will change from True to False in a future version.

What´s wrong here?

1 Answer 1

2

'[B]' is treated as a regular expression, which in this case means all characters within the brackets will be replaced (which is just B).

Use regex=False.

Sign up to request clarification or add additional context in comments.

Comments

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.