plotly 库有一些不错的桑基图https://plotly.com/python/sankey-diagram/ https://plotly.com/python/sankey-diagram/
但数据要求您传递源/目标对的索引。
link = dict(
source = [0, 1, 0, 2, 3, 3], # indices correspond to labels, eg A1, A2, A1, B1, ...
target = [2, 3, 3, 4, 4, 5],
我想知道是否有一个 API 可以简单地传递这些对的命名列表?
links = [
{'source': 'start', 'target': 'A', 'value': 2},
{'source': 'A', 'target': 'B', 'value': 2},
...
]
这更符合如何散景/全息视图 https://holoviews.org/reference/elements/bokeh/Sankey.html需要数据(但 sankey 不适用于自循环)
还有这个pysankey 小部件 https://nbviewer.jupyter.org/github/ricklupton/ipysankeywidget/blob/master/examples/Simple%20example.ipynb
这样我就可以更接近地映射到我的数据框而不处理所有内容?
或者,有没有一种很好的 Pythonic 方法可以将其转换为单行:D