import pandas as pd
#initialize the data
x = pd.DataFrame({'User':['A','A','A','B','B','C','C'],'Marketing_Channel':['Marketing_Channel','Email','Paid Search','Email','Paid Search','Email','Paid Search']})
#grouping by user to get the user journey
y = x.groupby('User').agg({'Marketing_Channel': '->'.join}).reset_index()
#group by channel to get the count
z = y.groupby('Marketing_Channel').count()
#make a json out of it
z.to_json()
要分解它:
groupby('User')['Marketing_Channel'].apply(list)
将Marketing_Channel
的值聚合到每个User
的值列表中str.join(" -> ")
将列表加入到每个操作的路径中.value_counts().to_dict()
计算唯一路径的数量并转换为字典对于此示例数据,
counts
包含:这对我很有用:
相关问题 更多 >
编程相关推荐