ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). df[condition]

Solution 1:

As Michael Szczesny also pointed out in the comment. DataFrame.apply uses a Series as input. The change(name) function defined expects a string. The message ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). comes from trying to compare a Series to a string.

One fix pointed out by Register Sole is to use conditions instead.

condition = (df[‘embark_town’] == 'Southampton')
df[condition]['embark_town'] = 'Manchester'

To keep using apply, the change function would need to look something like this:

def change(series):
  if series.name == 'embark_town':
      series[series.values == 'Southampton'] = 'Manchester'

  return series