Pandas Filter by Date How can I filter a CSV with Dates
Example CSV
User Dates Hours shift
User1 01.01.2012 5 aaa
User1 02.01.2012 5 aaa
User1 03.01.2012 2 bbb
User1 04.01.2012 3 aaa
.....
User1 12.03.2012 1 aaa
User1 13.03.2012 8 ccc
.....
User2 04.02.2012 4 aaa
User2 05.02.2012 3 bbb
end so on
I can filter by a User with
use = users.loc["User1"]
also I can sum all Hours
print(use["Hours"].sum()
and I can count his shifts
counts = use.loc[ou['Shift'] == 'aaa', 'Hours'].value_counts()
But I dont know how I can filter by the Date and and the Statements above. Like count all shifts in March by User2 or Sum all Hours done in Feb by User1
More or less I manged to Filter the Table by Date and User with
use['Date'] = pd.to_datetime(use['Date'], infer_datetime_format=True, exact=True)
mask = (use['Datum'] > Start) & (use['Date'] <= End)
print(use.loc[mask])
But I cant figure out how to combine them. Desired Output
Overview March 2016
User1 made 3 aaa shifts
User1 worked 12h in March 2016
update: I made some progress
print(use[use['Date'] > '02.01.2012'],['hours'].sum()))
works fine but not exctly what I want. With:
print(use[use['Date'] > '02.01.2012'] & (use[use['Date'] < '02.05.2012'],['hours'].sum()))
I get
AttributeError: 'list' object has no attribute 'sum'