我如何在atoti的where条件中输入日期?

2024-06-28 15:27:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图对日期层次结构应用以下条件:

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值,但dates列不包含任何NA值


Tags: langstring层次结构timejava条件aggclass
1条回答
网友
1楼 · 发布于 2024-06-28 15:27:30

免责声明:我是atoti的开发者


您需要在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"]])
+      +                 -+
| date       | additional_refrigerator_equipped2 |
+      +                 -+
| 2019-10-31 | 0                                 |
+      +                 -+
| 2019-11-01 | 0                                 |
+      +                 -+
| 2019-11-02 | 500                               |
+      +                 -+
| 2019-11-03 | 500                               |
+      +                 -+

相关问题 更多 >