0

I am receiving a dataframe from source which looks like this:

date          output
2023-01-25    A
2023-01-25    B
2023-01-25    B
2023-01-25    C
2023-01-25    C
2023-01-25    A
2023-01-25    B
     ...
2023-01-26    B
2023-01-26    C
2023-01-26    B
2023-01-26    B
2023-01-26    A
2023-01-26    C
2023-01-26    B
     ...
2023-01-27    C
2023-01-27    A
2023-01-27    A
2023-01-27    C
2023-01-27    B
2023-01-27    B

For my pipeline I need to transform this data.

After using df.groupby('Date').output.value_counts() I was able to get following result:

Date        output
2023-01-25  A             52
            B             28
            C             42
2023-01-26  A             47
            B             32
            C             36
2023-01-27  A             23
            B             67
            C             35

But for my pipeline I need dataframe in following structure:

Date        A              B              C
2023-01-25  52             28             42
2023-01-26  47             32             36
2023-01-27  23             67             35

How can I store all these value counts to its respective column so result looks like above?

0 Answers0