I want to replace every string in my pandas df column departments with None if it contains a )
departments var1 var1.1
1 transport aa uu
2 industry) bb tt
3 aviation) cc tt
how the dataset should look like
departments var1 var2
1 transport aa uu
2 None bb tt
3 None cc tt
A similar solution is here: Replacing regex pattern with another string works, but replacing with NONE replaces all values
How can i transform it to base python as i dont use spark?
df.withColumn("departments", when(col("departments").rlike("\)"), None)
.otherwise(col("departments"))
)