MMM
MMM

Reputation: 435

python pandas data frame replace ends of string values to another character

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?

Upvotes: 2

Views: 202

Answers (1)

Vaishali
Vaishali

Reputation: 38415

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

Upvotes: 3

Related Questions