python - 如何设置Pandas数据框where条件的多个值

标签 python pandas

我想设置 pandas 数据框列的多个值 where 条件,但收到错误消息:

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

最佳答案

试试这个:

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

关于python - 如何设置Pandas数据框where条件的多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41593389/

相关文章:

python - Cython 导入工作一次 - 然后给出 gcc.bat 错误

python - 使用 Sklearn 的 TfidfVectorizer 变换

python - 如何删除值频率小于 5 的行? python , Pandas

Python 数据帧 : find previous row's value before a specific value with same value in other columns

python - pandas - 按列名屏蔽数据框

python - 如何相互检查两个列表?

python - 如何将 Pandas 数据框中的对象转换为日期时间?

python - Django ORM 查询 - 如何从模型字段中减去时间?

python - 如何对具有组合列表的 Pandas 数据框进行分组?

python - 将缺失数据添加到按日期分组的数据框中