I have code below that gives me number of times a professor has a value for true or false ( true being 1 ) for various columns as:
df below as:
Name | Factory | Restaurant | Store | Building
Brian True False True False
Mike True True True True
Brian True False False True
Sam False False False False
Sam True False True True
Mike True False False False
cols = ['Factory', 'Restaurant', 'Store', 'Building'] ( because df has other columns I dont want to calc)
df = df.groupby('Name', as_index=False)[cols].sum()
This gives me below:
Name | Factory | Restaurant | Store | Building
Brian 2 0 1 1
Mike 2 1 1 1
Sam 1 0 1 1
If I have another column in same df called status below like:
status
open
closed
open
closed
In the same df but I also want to group and calc the number of times it occurs by either open or closed how can I edit my code?
Basically output would have what I already have except it would say
Name Factory Open | Factory Closed... and so on
Brian 2 4
Mike 0 1
Thanks