vega-lite:跳过无效的值,而不是将其视为0的总和

发布于 2025-01-19 04:08:53 字数 2623 浏览 0 评论 0 原文

当在列上进行汇总总和并使用Vega-Lite对其进行绘制时,是否可以跳过无效的值,而不是在加法时将其视为0?当缺少/无效的数据时,我想显示它,而不是0

。 N4IgJAzgxgFgpgWwIYgFwhgF0wBwqgegIDc4BzJAOjIEtMYBXAI0poHsDp5kTykBaADZ04JAKyUAVhDYA7EABoQAEzjQATjRyZ289AHE2bMoLgByCAAIImNlADWlnJqhxLbUuss6EcSopUkTBRUUGIkQQY1NABtUGUguDQQACYABhSU-jSARn50gLJkpBwcUwgAgA9kgDkkGoCAT1r6kABfBXjE5PTM7LyCpSL0NnUkWTJopWr0HLSmnvmOrswk9F6s3PycwuTR8cmK6eSAZnmlZvQ6huXA1cW+rZSdoeSyMZwpkBmQABZzkCXVJLTp3NbAx4DFK7dAlMpfH7XBazEErcEbfr5aGvdDvEoI5JzZEgJFtAC6HRAmDGsggADNRghYqAoBEoAxBN10DgkOoIHAAGKCNhBAAUCUwDAQMTMlTMZIAlAEkBV0NVbqzBOzOfdubz+UKRZhxUEpTLGvKlUoVclmrckGR3nxdXEQGwcMkIFKAnSaHBBMpktVrarvu1Qe7Pd6lL7-YH0M0Q7b2mShuo2AwcExLjEwSAKaCGQHYmGLvmNWyOVyQJI2DRZKKYhKpZR7HBGqnLGYAPpmK0gG3ofmaaLkpRwWRQNjKevDUAzUCx4voCVJJSYRqfZKrBA4faCdqUzmNODqZkgCdTmcTNCgS6Lv3LkDhSJrqmb8EARwY4x0wR0pDhiAU7CmeoQgEu8YgMOfpHO+W7oLIbAIPWESHkoyDqPYyTCLISS3Je06zregIkZByQvlEAQbghIDfr+dBBDQgGUiBoxkY+UEwV8NHgkhKGyGhbSUph2HgbxyR7vWmDUUYgg6B64FTrIqwqckhHXkUwnkm0QA" rel="nofollow noreferrer">graph is what I expect when aggregating on date to get the sums for x y “在此处输入图像描述”

而在此example, the y两个行的值 date = 2022-01-20 是NAN,所以我希望没有数据点 y 并将其显示为缺失数据,而不是为0。 “在此处输入图像描述”

有没有办法做到这一点?我仔细研究了文档,但可能错过了一些东西。 I've tried using filter

我正在思考pandas groupby.sum(min_coun = 1),因此,如果至少没有1个非nan值,则结果将显示为NAN。

When doing an aggregate sum on a column and charting it using Vega-Lite, is it possible to skip invalid values instead of treating them as 0 when doing the addition? When there is missing/invalid data, I want to show it as such, rather than as 0.

For example, this graph is what I expect when aggregating on date to get the sums for x and y.
enter image description here

Whereas in this example, the y value for both rows where date=2022-01-20 are NaN, so I would want there to be no data point for the sum of column y and show it as missing data, instead of as 0.
enter image description here

Is there a way to do that? I’ve looked through the documentation but may have missed something. I've tried using filter like so, but that filters out an entire row, rather than just the invalid value of a particular column for the row when doing the sum.

I’m thinking something like pandas GroupBy.sum(min_coun=1), so that if there isn't at least 1 non-NaN value, then the result will be presented as NaN.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回忆追雨的时光 2025-01-26 04:08:53

好的,尝试将其删除Nan和Null但留下零。

Editor.

或这样可以消除无用转换的负载。

Editor< /a>

    {
      "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
      "description": "Google's stock price over time.",
      "data": {
        "values": [
          {"date": "2022-01-20", "g": "apples", "x": "NaN", "y": "NaN"},
          {"date": "2022-01-20", "g": "oranges", "x": "10", "y": "20"},
          {"date": "2022-01-21", "g": "oranges", "x": "30", "y": "NaN"},
          {"date": "2022-01-21", "g": "grapes", "x": "40", "y": "20"},
          {"date": "2022-01-22", "g": "apples", "x": "NaN", "y": "NaN"},
          {"date": "2022-01-22", "g": "grapes", "x": "10", "y": "NaN"}
        ]
      },
      "transform": [
        {"calculate": "parseFloat(datum['x'])", "as": "x"},
        {"calculate": "parseFloat(datum['y'])", "as": "y"},
        {"fold": ["x", "y"]},
        **{"filter": {"field": "value", "valid": true}},**
        {
          "aggregate": [{"op": "sum", "field": "value", "as": "value"}],
          "groupby": ["date", "key"]
        }
      ],
      "encoding": {"x": {"field": "date", "type": "temporal"}},
      "layer": [
        {
          "encoding": {
            "y": {"field": "value", "type": "quantitative"},
            "color": {"field": "key", "type": "nominal"}
          },
          "mark": "line"
        },
        {
          "encoding": {
            "y": {"field": "value", "type": "quantitative"},
            "color": {"field": "key", "type": "nominal"}
          },
          "mark": {"type": "point", "tooltip": {"content": "encoding"}}
        }
      ]
    }

OK, try this which removes NaN and null but leaves zero.

Editor.

Or this which removes a load of useless transforms.

Editor

    {
      "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
      "description": "Google's stock price over time.",
      "data": {
        "values": [
          {"date": "2022-01-20", "g": "apples", "x": "NaN", "y": "NaN"},
          {"date": "2022-01-20", "g": "oranges", "x": "10", "y": "20"},
          {"date": "2022-01-21", "g": "oranges", "x": "30", "y": "NaN"},
          {"date": "2022-01-21", "g": "grapes", "x": "40", "y": "20"},
          {"date": "2022-01-22", "g": "apples", "x": "NaN", "y": "NaN"},
          {"date": "2022-01-22", "g": "grapes", "x": "10", "y": "NaN"}
        ]
      },
      "transform": [
        {"calculate": "parseFloat(datum['x'])", "as": "x"},
        {"calculate": "parseFloat(datum['y'])", "as": "y"},
        {"fold": ["x", "y"]},
        **{"filter": {"field": "value", "valid": true}},**
        {
          "aggregate": [{"op": "sum", "field": "value", "as": "value"}],
          "groupby": ["date", "key"]
        }
      ],
      "encoding": {"x": {"field": "date", "type": "temporal"}},
      "layer": [
        {
          "encoding": {
            "y": {"field": "value", "type": "quantitative"},
            "color": {"field": "key", "type": "nominal"}
          },
          "mark": "line"
        },
        {
          "encoding": {
            "y": {"field": "value", "type": "quantitative"},
            "color": {"field": "key", "type": "nominal"}
          },
          "mark": {"type": "point", "tooltip": {"content": "encoding"}}
        }
      ]
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文