1

My df looks like this.

                 2019   2018
Sally#16#       -6461  -6340
Brian#06#        7139   7200
rebecca#9#       1337   1067
mark#10#        10922  11128
toto            12936  13054

Here, I would like to remove #number# from all my indexes. Is there a way to achieve this? probably with regex, so that I can have a final df like this:

                 2019   2018
Sally           -6461  -6340
Brian            7139   7200
rebecca          1337   1067
mark            10922  11128
toto            12936  13054

Thank you!

1 Answer 1

5

Use Series.str.replace with \d+ for select all numbers between #:

df.index = df.index.str.replace(r'(#\d+#)', '')
print (df)
          2019   2018
Sally    -6461  -6340
Brian     7139   7200
rebecca   1337   1067
mark     10922  11128
toto     12936  13054
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.