here is MRE:
df = pd.DataFrame({"hour":[1,2,2,3,3,6,6,6], "location":["a","a", "b","b","c","c","c","c"]})
which looks like this:
hour location
0 1 a
1 2 a
2 2 b
3 3 b
4 3 c
5 6 c
6 6 c
7 6 c
When I groupby hour and count number of time each hour occured I get
df.groupby(["hour"]).count()
>>> location
hour
1 1
2 2
3 2
6 3
In want to fill hours 4 and 5 and set its count to 0.
Here is what I desire:
location
hour
1 1
2 2
3 2
4 0
5 0
6 3
Previously I've used
df.groupby(["hour", "location"]).count().unstack(fill_value=0).stack()
Which I had no problem with but not working right now either.
I thought it is because this time I am grouping by only one column however when I groupby two columns it still doesn't work. I'm not sure why.