Reputation: 1
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
Upvotes: 0
Views: 39
Reputation: 13377
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
Upvotes: 3