1

Data looks like this

LIQUID PARAFFIN(1.25 MG)+MAGNESIUM HYDROXIDE(300.0 MG)+SODIUM PICOSULFATE(3.33 MG)

I have tried doing it by replace but it replace from first one parentheses to last close parentheses.

df['composition_replaced']=df["composition"].str.replace(r"\(.*\).\","")

Actual result-LIQUID PARAFFIN

Expected Result-

LIQUID PARAFFIN+MAGNESIUM HYDROXIDE+SODIUM PICOSULFATE
Vinay Hegde
  • 1,424
  • 1
  • 10
  • 23

1 Answers1

0

You can use this regex: \([^)]*\)

Here one example:

import pandas as pd

df = pd.DataFrame({"col1": ["LIQUID PARAFFIN(1.25 MG)+MAGNESIUM HYDROXIDE(300.0 MG)+SODIUM PICOSULFATE(3.33 MG)"]})   # Value to be plotted
print(df.values[0][0])
# LIQUID PARAFFIN(1.25 MG)+MAGNESIUM HYDROXIDE(300.0 MG)+SODIUM PICOSULFATE(3.33 MG)

df.col1 = df.col1.str.replace(r'\([^)]*\)', "")
print(df.values[0][0])
# LIQUID PARAFFIN+MAGNESIUM HYDROXIDE+SODIUM PICOSULFATE
Alexandre B.
  • 5,387
  • 2
  • 17
  • 40
  • Glad to help you ! Feel free to accept the answer if that solves the issue, Upvote / downvote answer [have a look here](https://stackoverflow.com/help/someone-answers) – Alexandre B. Jun 29 '19 at 10:32
  • 1
    On this site, show your appreciation by upvoting all the useful answers. You do that by clicking the up-arrow at the top-left of the answer, if you have enough reputation to do so. In addition, accept the best answer (if it actually answers your question) by clicking the checkmark near the top-left of the answer. That is better than saying thanks in a comment. It also helps others to see that your question was answered. – Rory Daulton Jun 29 '19 at 11:05
  • 1
    Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score.-I receive this message. – Aditya Kulkarni Jun 30 '19 at 06:18