I have an info frame 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 add text ('-s') to everything that is 4 characters long. I tried unsuccessfully below. since it causes an error, ValueError: the value of the series truth is ambiguous. Use the a.empty, a.bool (), a.item (), a.any (), or a.all () commands.
if a['Id'].str.len() == 3: a['Id'] = a['Id'].str.replace('s', '-s') else: pass
source share