You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vega-Lite缺失value数据填充失效及全量填充异常求助

无法填充Vega-Lite数据中的缺失值

数据中2011-04-05的条目没有value字段,而是包含missing字段,尝试多种impute配置均无法填充该缺失值。

原始Vega-Lite配置

{"$schema": "https://vega.github.io/schema/vega-lite/v5.json","data": {"values": [{"timestamp": "2011-04-01T17:06:21.000Z","value": 0.44777528325189986},{"timestamp": "2011-04-02T17:06:21.000Z","value": 0.44390285331388984},{"timestamp": "2011-04-03T17:06:21.000Z","value": 0.44813958999449255},{"timestamp": "2011-04-04T17:06:21.000Z","value": 0.4440416510172272},{"timestamp": "2011-04-05T17:06:21.000Z","missing": "NO value KEY HERE!"},{"timestamp": "2011-04-06T17:06:21.000Z","value": 0.3797480270068858},{"timestamp": "2011-04-07T17:06:21.000Z","value": 0.31955288375970203},{"timestamp": "2011-04-08T17:06:21.000Z","value": 0.3171368880067786},{"timestamp": "2011-04-10T17:06:21.000Z","value": 0.30021395605134893},{"timestamp": "2011-04-11T17:06:21.000Z","value": 0.3130485242947531}]},"encoding": {"y": {"field": "timestamp","type": "temporal","sort": "ascending"}},"layer": [{"mark": {"type": "line","interpolate": "cardinal"},"encoding": {"x": {"field": "value","sort": null,"type": "quantitative","axis": {"orient": "top"},"impute": {"keyvals": ["value"],"method": "mean","frame": [-5, 5]}}}}]}

原本以为以下impute配置能填补缺失值:

"impute": {"keyvals": ["value"], "method": "mean", "frame": [-5, 5]}

尝试了多种配置组合,均未生效:

  • 将keyvals改为["timestamp"]
  • 将impute配置移至"encoding": {"y": ...}定义内
  • 同时执行上述两个操作

更新1:尝试transform中的impute配置

在transform中添加impute配置,依然无效:

{"$schema": "https://vega.github.io/schema/vega-lite/v5.json","data": {"values": [...]},"transform": [{"impute": "value","key": "timestamp","frame": [-1, 1],"method": "mean"}],"encoding": {"y": {"field": "timestamp","type": "temporal","sort": "ascending"}},"layer": [{"mark": {"type": "line","interpolate": "cardinal"},"encoding": {"x": {"field": "value","sort": null,"type": "quantitative","axis": {"orient": "top"}}}}]}

更新2:非预期的填充结果

使用transform的impute配置后,系统生成了文档未提及的imputed_value_value字段(而非原value字段)。该配置确实完成了填充,但会对所有数据进行均值计算填充,而我仅希望填充缺失的数据。这是impute的预期行为吗?

对应的配置:

{"$schema": "https://vega.github.io/schema/vega-lite/v5.json","data": {"values": [...]},"transform": [{"impute": "value","key": "timestamp","frame": [-5, 5],"method": "mean"}],"encoding": {"y": {"field": "timestamp","type": "temporal","sort": "ascending"}},"layer": [{"mark": {"type": "line","interpolate": "cardinal"},"encoding": {"x": {"field": "imputed_value_value","sort": null,"type": "quantitative","axis": {"orient": "top"}}}}]}

内容的提问来源于stack exchange,提问作者Connor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 14:55:23