Here is the data.
day_value = {
'android':[1,0,0,0,0,0,1],
'iphone':[0,1,0,1,0,0,0],
'web':[0,1,1,0,1,0,0],
}
device_rollup = {
'overall':['iphone','android','web'],
'mobile':['iphone','android'],
}
rollup_l7 = {
'overall': 6,
'mobile': 4,
}
If the values are same on each column we must rollup as 1 not add it up. The total for overall should be 6 ((1,0,0)+(0,1,1)+(0,0,1)+(0,1,0)+ (0,0,1)+ (1,0,0)-> 1+1+1+1+1+1 =6)
Now I can add up all the values like this.
overall_val = sum(sum(v) for k,v in day_value.items() if k in device_rollup['overall'] )
mobile_val = sum(sum(v) for k,v in day_value.items() if k in device_rollup['mobile'] )
rollup_l7= {'overall':overall_val, 'mobile':mobile_val}
print(rollups_l7)
But, I don't want to add up instead I would like to roll up each columnar value.
Do we need to convert the list to binary and then covert back to integer?
I am not quite sure how I can achieve in regular python without using numpy