How to set multiple values of Pandas dataframe where condition

I want to set multiple values of pandas dataframe columns where a condition, but I got an error message:

df[df['store_id'] == 'UK00023', ['sale','startdate','enddate']] = [100, str(datetime.now()), str(datetime.now())]

But I got this error:
    raise ValueError('Length of values does not match length of '
ValueError: Length of values does not match length of index

1 answer

  • answered 2017-01-11 14:25 DougKruger

    Try this:

    df.ix[df['store_id'] == 'UK00023', ['sale','startdate','enddate']] = [100, str(datetime.now()), str(datetime.now())]