首页 > 解决方案 > 如何在 attoti 的 where 条件下设置日期?

问题描述

我正在尝试在日期层次结构上应用以下条件:

m["additional_refrigerator_equipped2"] = tt.agg.sum(
    tt.where(lvl["date"] > "2019-11-01", 500, 0))

我在可视化上收到以下错误:

An error happened during the loading process: "class java.lang.String cannot be cast to class 
java.time.chrono.ChronoLocalDate (java.lang.String and java.time.chrono.ChronoLocalDate
are in module java.base of loader 'bootstrap')"

如何将日期添加到比较中?

我还检查了 NA 值,但日期列不包含任何 NA 值。

标签: pythonolapjupyter-labolap-cubeatoti

解决方案


免责声明:我是 attoti 的开发人员


您需要在 where 条件中使用 Python 日期对象而不是字符串:

import datetime as dt

m["additional_refrigerator_equipped2"] = tt.agg.sum(
    tt.where(lvl["date"] > dt.date(2019,11,1), 500, 0)
)

在一个包含 4 个日期的简单示例中,它给出的结果如下:

cube.query(m["additional_refrigerator_equipped2"], levels=[lvl["date"]])
+------------+------------------------------------------------+
| 日期 | Additional_refrigerator_equipped2 |
+------------+------------------------------------------------+
| 2019-10-31 | 0 |
+------------+------------------------------------------------+
| 2019-11-01 | 0 |
+------------+------------------------------------------------+
| 2019-11-02 | 500 |
+------------+------------------------------------------------+
| 2019-11-03 | 500 |
+------------+------------------------------------------------+

推荐阅读