我可能有一个小问题,但实际上我找不到解决办法。
我的数据如下所示: data
我想创建一个旅程,从而实现了转化,就像这样:
1:a> b> a> b
2:c> b> a> a
但是,目前,结果看起来像这样:
1:a> b> a> b
2:a> b> c> b> a> a
第二个人从我的第一位用户那里得到了一些旅程点。
我的问题是:如何按visid对旅程进行分组?
我的代码:
transition_matrix = list()
counter = 0
journey = ''
order_id_flag = False
for row in time_data:
# Set cust_visid and order information
current_cust_id = row['cust_visid'] if row['cust_visid'] else 0
netto = row['netto'] if row['netto'] else 0
menge = row['menge'] if row['menge'] else 0
buytype = row['buytype'] if row['buytype'] else 0
if row['marketing_campaign']: # check if marketing_campaign filled
# Extract Touchpoint
touch_point = re.search(r'(\w+)\.',row['marketing_campaign']).group(1)
# Add to User-Journey
journey += touch_point + ' > '
if row['js_order_id']: # if an order id exists
order_id_flag = True # set flag for filled js_order_id
if order_id_flag: # check if js_order_id was filled in previous iteration
transition_matrix.append([current_cust_id,journey.strip(' > '),menge,netto,buytype]) # add to list
# Reset Variables
journey = ''
order_id_flag = False
current_cust_id = ''