This has to be the easiest thing to do I just can't figure it out.
I have a dataframe like this:
station ts EventType
0 BLOOR 2020-02-04 20:35:00 Valid Entry
1 BLOOR 2020-02-07 17:45:00 Valid Exit
2 COLLEGE 2020-02-05 14:20:00 Valid Exit
3 BAY 2020-02-04 16:55:00 Valid Entry
4 UNION 2020-02-07 08:20:00 Valid Exit
and I just want a dataframe that splits the "EventType" column and counts them grouped by station and ts:
station ts EntryCount ExitCount
0 BLOOR 2020-02-04 20:35:00 5 2
1 BLOOR 2020-02-04 20:40:00 10 6
2 COLLEGE 2020-02-04 20:35:00 3 7
3 COLLEGE 2020-02-04 20:40:00 6 8
4 COLLEGE 2020-02-04 20:45:00 5 9
I've started down these paths unsuccessfully:
df.pivot_table(index=['station','ts'], columns="EventType", values="EventType", aggfunc=sum)
or
df['EntryCount'] = df.groupby(["ts", "station"], as_index=False, sort=False)["EventType"].apply(
lambda etype: etype == "Valid Entry"
).sum()
(worth mentioning- the dataframe is quite large as well)