I have a Dataframe that looks like this:
OrdNo year
1 20059999
2 20070830
3 20070719
4 20030719
5 20039999
6 20070911
7 20050918
8 20070816
9 20069999
How to replace last 4 digits in the Pandas Dataframe by 0101 if they are 9999?
Thanks
>Solution :
Assuming your year column is of type str:
df["year"] = df["year"].str.replace("(9999)$", "0101")
If it is of numeric type
df["year"] = pd.to_numeric(df["year"].astype(str).str.replace("(9999)$", "0101"), errors="coerce")