Pivoting results

df = DataFrame();
df[!,:Vintage] = ["2021-01-31","2021-01-31","2021-01-31","2021-02-28","2021-02-28",
    "2021-03-31","2021-04-30","2021-04-30"];
df[!,:Grade] = ["A","B","C","C","A","B","C","D"];
df[!,:Amt] = [2000000,999999,850000,450150,5075000,775000,625000,575000];
df

# Desired output:
desired = DataFrame();
desired[!,"Grade"] = ["A","B","C","D"];
desired[!,"01-31-21"] = [2000000,999999,850000,0];
desired[!,"02-28-21"] = [5075000,0,450150,0];
desired[!,"03-31-21"] = [0,775000,0,0];
desired[!,"04-30-21"] = [0,0,625000,575000];
desired

Can someone tell me why the below does not work?

desired = df |>
    groupby(:Grade) |>
    pivot_table(values = :Amt, cols = pd.to_datetime(:Vintage), aggfunc = sum, fill_value = 0) |>
    rename!(cols = x -> Dates.format(x, "m-dd-y"))

Hi welcome to the Julia Discourse!

Please follow these instructions to make your code easier to read for us

I think this is what you need:

df = DataFrame();
df[!,:Vintage] = [“2021-01-31”,“2021-01-31”,“2021-01-31”,“2021-02-28”,“2021-02-28”,
“2021-03-31”,“2021-04-30”,“2021-04-30”];
df[!,:Grade] = [“A”,“B”,“C”,“C”,“A”,“B”,“C”,“D”];
df[!,:Amt] = [2000000,999999,850000,450150,5075000,775000,625000,575000];
df

unstack(df, :Grade, :Vintage, :Amt, combine=mean, fill=0)

AWESOME! Thanks GSINHA! Only adjustment is the “mean” to “sum”.

Thank you!