Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. |App_Flag|ATL_Flag|Cust_No|month1|month2
  2. | 0 | TV | 1 | 1 | 0
  3. | 0 | FB | 1 | 0 | 0
  4. | 0 | OOH | 1 | 1 | 1
  5. | 1 | RAD | 2 | 1 | 1
  6. | 1 | TV | 2 | 1 | 0
  7. | 1 | FB | 2 | 1 | 0
  8.  
  9. def str_sum(channel):
  10. return '>'.join(channel['c_path'])
  11.  
  12. 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')
  13. wrk_data_temp['variable'] = wrk_data_temp['variable'].str.extract(r'([d]+)').astype(int)
  14. 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')
  15. wrk_data_temp2 = wrk_data_temp[['cust_no', 'variable', 'c_path']].drop_duplicates()
  16. wrk_data_temp3 = wrk_data_temp2.dropna()
  17. 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