Python-在floweaver中合并包

问题描述 投票:2回答:1

我有一组用户在网站上的点击列表。我正在尝试通过网站创建点击流。使用下面的代码,我得到以下结果。 我想将第一个捆绑包的末尾与第二个捆绑包的末尾连接在一起,否则看起来很奇怪。

import floweaver as fw
import pandas as pd

df = pd.DataFrame(
    data={'event_no': [1, 1, 1, 2, 2, 2, 2, 2, 3, 3],
          'source': ['Home', 'Home', 'Home', 'Products', 'Products', 'Products', 'About', 'About', 'Product1', 'Product1'],
          'target': ['About', 'Products', 'Other', 'Product1', 'Product2', 'Product3', 'Products', 'Other', 'Buy', 'Buy'],
          'value': [100, 300, 150, 150, 75, 50, 50, 10, 20, 10]}
)

size = {'width': 600, 'height': 600}
nodes = {
    'Event1': fw.ProcessGroup(df.loc[df['event_no'] == 1, 'source'].unique().tolist()),
    'Event2': fw.ProcessGroup(df.loc[df['event_no'] == 2, 'source'].unique().tolist()),
    'Event3': fw.ProcessGroup(df.loc[df['event_no'] == 3, 'source'].unique().tolist())
}
ordering = [
    ['Event1'],
    ['Event2'],
    ['Event3']
]
bundles = [
    fw.Bundle('Event1', 'Event2'),
    fw.Bundle('Event2', 'Event3')
]
nodes['Event1'].partition = fw.Partition.Simple('source', df.loc[df['event_no'] == 1, 'source'].unique())
nodes['Event2'].partition = fw.Partition.Simple('source', df.loc[df['event_no'] == 2, 'source'].unique())
nodes['Event3'].partition = fw.Partition.Simple('source', df.loc[df['event_no'] == 3, 'source'].unique())

sdd = fw.SankeyDefinition(nodes, bundles, ordering)
fw.weave(sdd, df).to_widget(**size)

enter image description here

[我尝试使用一个航路点,该航路点在两个事件之间只有一个事件时有效,但是由于某些原因,当我有4个以上event_no并使用[2,3,...]作为航路点时,它将不起作用。

任何想法如何使这项工作?

python sankey-diagram
1个回答
0
投票

分区时,需要使用process类。将三个都更改为:fw.Partition.Simple('process', df.loc[df['event_no'] == 1, 'source'].unique()),您将被设置。

© www.soinside.com 2019 - 2024. All rights reserved.