0

I have this DataFrame:

d = {'col1': ['(-99999.0, -99998.0]', '(-99998.0, 1.0]','(1.0, 10]']}
df = pd.DataFrame(data=d)
print(df)

which looks like this:

                   col1
0  (-99999.0, -99998.0]
1       (-99998.0, 1.0]
2             (1.0, 10]

I need to replace the square bracket ] with a round bracket ), so that the dataframe looks like this:

                   col1
0  (-99999.0, -99998.0)
1       (-99998.0, 1.0)
2             (1.0, 10)

How do I do it?

3
  • df['col1'] = df['col1'].str.replace('\]',')', regex=True) Commented Feb 15, 2022 at 22:34
  • Yes ! thanks ! That answers it ! Commented Feb 15, 2022 at 22:34
  • df['col1'] = df['col1'].apply(lambda x: str(x).replace("]",')')) Commented Feb 15, 2022 at 22:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.