Capitalize text between parentheses in pandas column

Question:

I have a pandas column that contains a list of text:

["apple", "orange (fruit)", "banana"]

I would like to capitalize the text between the parentheses of the text so that the final output would be:

["apple", "orange (FRUIT)", "banana"]
Asked By: Santa

||

Answers:

You can use Series.str.replace with a regular expression:

col.str.replace(r"(.+)", lambda x: x.group(0).upper(), regex=True)

This outputs:

0             apple
1    orange (FRUIT)
2            banana
Answered By: BrokenBenchmark
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.