python - 如何在 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 值。
解决方案
免责声明:我是 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 | +------------+------------------------------------------------+
推荐阅读
- javascript - 如何在锚标签点击下载图像文件而不在新标签中打开图像?
- c - 读取特定格式的字符串
- r - 格式化 y 轴数字
- distributed-computing - PAXOS 算法共识之谜
- bash - 将getopts选项自动解析为bash中同名的动态变量
- python - Jupyter Notebook 内核一直很忙
- java - 创建拍卖清单 (java)
- c# - Application.Current.Dispatcher.BeginInvoke(action) VS。Application.Current.Dispatcher.Invoke(action) (WPF)
- sharepoint - SharePoint 2013 CSOM 上传文档和更改列值
- r - 如何将变量值重置为 0 作为起点?