I have a pandas dataframe db3 where I'm trying to come up with a function that could be applied to each row in ColA that would replace oldStrings (if found) with a newString. The output would be shown in new ColB. Here is where I've gotten so far:
oldString = [' ','-']
newString = '_'
def replaceCharacters(x):
return x.replace(oldString,newString)
for index, row in db3.iterrows():
if any(x in row['colA'] for x in oldString):
db3['ColB'] = db3.apply(lambda row: replaceCharacters(db3['ColA']), axis=1)
This is throwing an error "wrong number of items passed.." Any ideas what I could be doing wrong or how to accomplish this in python?