I am currently having difficulty replacing a string in my pandas dataframe. So the string that I want to change is "private" -> "pte" and "limited" -> "ltd".
The table looks like:
Column: Company_Name
1. XXXX private limited
2. XX (private) limited
3. yyy pte. limited
My code is:
df['company_name'].str.replace('.*private.+*','pte')
df['company_name'].str.replace('limited$','ltd)
print(df)
But I still get the exact same dataframe that I used pandas to read. Does anybody know why - I checked that I imported re?
str.replaceis not inplace, it returns the modified Series/column, you need to assign back:df['company_name'] = df['company_name'].str.replace('.*private.+*','pte'), check the docs