I have a dataset which has Id , ActivityDate and TotalSteps as column header. Please find dataframe details below:
df = pd.DataFrame([[1844505072, 6847, '4/1/2016'], [1844505072, 5367, '4/2/2016'], [1844505072, 0, '4/3/2016'],[1844505072, 0, '4/4/2016']], columns=['Id', 'TotalSteps','ActivityDate'])
Id TotalSteps ActivityDate
1844505072 6847 4/1/2016
1844505072 5367 4/2/2016
1844505072 0 4/3/2016
1844505072 0 4/4/2016
Need to find the total steps taken by each id and also the count when total_steps = 0. In the above set , expected result is:
Id TotalSteps Zero_steps
1844505072 12214 3
Below code is written using pandas which gives two separate results. I want all results to be in a single dataframe.
df[df['Id']==1844505072].groupby('Id').agg(Sum_Tot_Steps=('TotalSteps','sum'))
df[df['Id']==1844505072].groupby('Id')['TotalSteps'].apply(lambda x:x[x==0].count())
Please provide any solution using python pandas. Thanks for your help.