小编gee*_*mer的帖子

从 timeserie 数据帧绘制桑基图

我有一个数据框A

date        Cluster    count Users 
01/01/2021  ClusterA    10
01/01/2021  ClusterB    10
01/01/2021  ClusterB    9
02/01/2021  ClusterA    14
02/01/2021  ClusterB    10
02/01/2021  ClusterB    5
Run Code Online (Sandbox Code Playgroud)

我想可视化集群之间的用户迁移,为此,我首先生成以下 dataframeB :

date        Source     Target    Value 
02/01/2021  ClusterA   ClusterA   8
02/01/2021  ClusterA   ClusterB   2
02/01/2021  ClusterB   ClusterB   8
02/01/2021  ClusterB   ClusterA   2
02/01/2021  ClusterC   ClusterA   4
02/01/2021  ClusterC   ClusterC   5
Run Code Online (Sandbox Code Playgroud)

我画了桑基图:

import plotly.graph_objects as go
label = ["ClusterA01/01/2021","ClusterB01/01/2021","ClusterC01/01/2021","ClusterA02/01/2021","ClusterB02/01/2021","ClusterC02/01/2021"]
source = [0, 0, 1, 1, 2,2]
target = [3, 4, 3, 4, 3,5]
value = [8, 2, …
Run Code Online (Sandbox Code Playgroud)

python plotly sankey-diagram plotly-python

5
推荐指数
1
解决办法
877
查看次数

标签 统计

plotly ×1

plotly-python ×1

python ×1

sankey-diagram ×1