I have a dataframe below.
a = {'Id': ['ants', 'bees', 'cows', 'snakes', 'horses'], '2nd Attempts': [10, 12, 15, 14, 0],
'3rd Attempts': [10, 10, 9, 11, 10]}
a = pd.DataFrame(a)
print (a)
I want to able add text ('-s') to anything which is equal to 4 characters. i have unsuccessfully tried the below. as it produces the error, ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
if a['Id'].str.len() == 3:
a['Id'] = a['Id'].str.replace('s', '-s')
else:
pass