2

I want to replace ends of string values in one column to another character. Here, I want to convert every ends of string values to '0'. The values in 'Codes' column are string.

e.g

    Code    
1   11-1111
2   12-2231
3   12-1014
4   15-0117
5   16-2149

to

    Code    
1   11-1110
2   12-2230
3   12-1010
4   15-0110
5   16-2140

What method I can use?

1 Answer 1

3

One way could be

df.Code = df.Code.str[:-1] + '0'

You get

    Code
1   11-1110
2   12-2230
3   12-1010
4   15-0110
5   16-2140
Sign up to request clarification or add additional context in comments.

3 Comments

You can't beat that solution. +1
Thank you! You made my Friday:)
Happy weekends +1

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.