Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- |App_Flag|ATL_Flag|Cust_No|month1|month2
- | 0 | TV | 1 | 1 | 0
- | 0 | FB | 1 | 0 | 0
- | 0 | OOH | 1 | 1 | 1
- | 1 | RAD | 2 | 1 | 1
- | 1 | TV | 2 | 1 | 0
- | 1 | FB | 2 | 1 | 0
- def str_sum(channel):
- return '>'.join(channel['c_path'])
- wrk_data_temp = pd.melt(work_data_temp[['cust_no', 'ATL_Flag', 'max_exp_1_mnth', 'max_exp_2_mnth']], id_vars=['cust_no', 'ATL_Flag'], value_vars=['max_exp_1_mnth', 'max_exp_2_mnth'], value_name='key')
- wrk_data_temp['variable'] = wrk_data_temp['variable'].str.extract(r'([d]+)').astype(int)
- wrk_data_temp['c_path'] = wrk_data_temp.sort_values(['cust_no', 'variable', 'ATL_Flag'])[wrk_data_temp.key == 1][['cust_no', 'ATL_Flag', 'variable']].groupby(['cust_no', 'variable']).transform('sum')
- wrk_data_temp2 = wrk_data_temp[['cust_no', 'variable', 'c_path']].drop_duplicates()
- wrk_data_temp3 = wrk_data_temp2.dropna()
- final = pd.DataFrame(wrk_data_temp3[['cust_no', 'c_path']].groupby('cust_no').apply(str_sum))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement