如何在条件中设置Pandas数据帧的多个值

时间:2017-01-11 14:25:04

标签: python pandas

我想设置一个条件的pandas dataframe列的多个值,但是我收到了一条错误消息:

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 个答案:

答案 0 :(得分:3)

试试这个:

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