I think the best way is to use Query.jl
using DataFrames, Query
df = DataFrame(name=["John", "Sally", "Kirk", "Sanders"], age=[23., 42., 59., 31.], children=[3,2,2,0], date=[Date("2015-01-01"),Date("2015-01-10"),Date("2015-02-20"), Date("2015-02-05")])
x = df |>
@groupby(Dates.format(_.date, "yyyy-mm")) |>
@map({Key=key(_), Count=length(_)}) |>
DataFrame
println(x)
2×2 DataFrame
│ Row │ Key │ Count │
│ │ String │ Int64 │
├─────┼─────────┼───────┤
│ 1 │ 2015-01 │ 2 │
│ 2 │ 2015-02 │ 2 │