0

I have a dataframe with Column[ID] and values ('123456','102554','0145220','1554201','0155401','0101010110','0101010105') If last 2 characters of the column starts with 0 then update the value without that 0

Final result of dataframe should be ('123456','102554','0145220','155421','015541','0101010110','010101015')

Please help

1 Answer 1

3

You can leverage pd.Series.replace(..., regex=True):

df["ID"] = df["ID"].replace("^(.*)0(.)$", "\\1\\2", regex=True)

Outputs:

           ID
0      123456
1      102554
2     0145220
3      155421
4      015541
5  0101010110
6   010101015
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.