I have a dataframe ('frame') on which I want to aggregate by Country and Date:
aggregated=pd.DataFrame(frame.groupby(['Country','Date']).CaseID.count())
aggregated["Total duration"]=frame.groupby(['Country','Date']).Hours.sum()
aggregated["Mean duration"]=frame.groupby(['Country','Date']).Hours.mean()
I want to compute the above figures (total duration, mean duration, etc.) only for the positive 'Hours' numbers in 'frame'. How can I do that?
Thanks!
Sample "frame"
import pandas as pd
Line1 = {"Country": "USA", "Date":"01 jan", "Hours":4}
Line2 = {"Country": "USA", "Date":"01 jan", "Hours":3}
Line3 = {"Country": "USA", "Date":"01 jan", "Hours":-999}
Line4 = {"Country": "Japan", "Date":"01 jan", "Hours":3}
pd.DataFrame([Line1,Line2,Line3,Line4])