Pandas aggregate with dynamic column namesSelecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame“Large data” work flows using pandasChange data type of columns in PandasHow to iterate over rows in a DataFrame in Pandas?How to select rows from a DataFrame based on column values?Get list from pandas DataFrame column headers

Can someone purchase a google subdomain?

Pass arguments to the list of functions?

Scientific Illustration: Non-photorealistic rendering of sparse wireframe with dashed/dotted lines for backfacing areas - Blender 2.80

What anti-aircraft magic adaptation would be better for dragons than flame spitting?

Enumeration with direct and indirect properties

Cooking with sugar makes pan very difficult to clean

Center a DIV unequally using CSS

Unstable manifolds of a Morse function give a CW complex

Can I call the airport to see if my boyfriend made it through customs?

Suggested idea: Course exams written by someone else other than the instructors/coordinators. Good or Bad?

Can the Fortress spell be dispelled?

According to limits there is a horizontal asymptote at y = 0, however the equation has a root at x = 1. Help!

Did the Apollo missions fly "over the top" of the Van Allen radiation belts?

Is there any theory why (for Bitcoin) the discrete logarithm problem is so hard to solve?

Caro-Kann advance variation w/ 3. c5 dxc5

If I wanted to reconstruct an entire Apollo mission's crewed spacecraft trajectories, what are the key sources of historical data I'd look for?

How can I run a realistic open-world game with vast power differences, without resulting in constant TPKs?

Do one quarter of Swedes named 'Ali' have a criminal record?

Cheap and safe way to dim 100+ 60W Incandescent bulbs

How can an AI train itself if no one is telling it if its answer is correct or wrong?

What is this nut?

How can I offer my prayers to an atheist colleague facing a serious personal situation?

What does ゴン part in イノゴン mean?

Why, in the US, are politicians tried by other politicians?



Pandas aggregate with dynamic column names


Selecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame“Large data” work flows using pandasChange data type of columns in PandasHow to iterate over rows in a DataFrame in Pandas?How to select rows from a DataFrame based on column values?Get list from pandas DataFrame column headers






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









22


















I have a script that generates a pandas data frame with a varying number of value columns. As an example, this df might be



import pandas as pd
df = pd.DataFrame(
'group': ['A', 'A', 'A', 'B', 'B'],
'group_color' : ['green', 'green', 'green', 'blue', 'blue'],
'val1': [5, 2, 3, 4, 5],
'val2' : [4, 2, 8, 5, 7]
)

group group_color val1 val2
0 A green 5 4
1 A green 2 2
2 A green 3 8
3 B blue 4 5
4 B blue 5 7


My goal is to get the grouped mean for each of the value columns. In this specific case (with 2 value columns), I can use



df.groupby('group').agg("group_color": "first", "val1": "mean", "val2": "mean")

group_color val1 val2
group
A green 3.333333 4.666667
B blue 4.500000 6.000000


but that does not work when the data frame in question has more value columns (val3, val4 etc.).
Is there a way to dynamically take the mean of "all the other columns" or "all columns containing val in their names"?










share|improve this question



























  • is group_color always the same for one group?

    – Quang Hoang
    Sep 18 at 13:56











  • @QuangHoang: yes, that is the case, but I would still like to retain it

    – MartijnVanAttekum
    Sep 18 at 14:02

















22


















I have a script that generates a pandas data frame with a varying number of value columns. As an example, this df might be



import pandas as pd
df = pd.DataFrame(
'group': ['A', 'A', 'A', 'B', 'B'],
'group_color' : ['green', 'green', 'green', 'blue', 'blue'],
'val1': [5, 2, 3, 4, 5],
'val2' : [4, 2, 8, 5, 7]
)

group group_color val1 val2
0 A green 5 4
1 A green 2 2
2 A green 3 8
3 B blue 4 5
4 B blue 5 7


My goal is to get the grouped mean for each of the value columns. In this specific case (with 2 value columns), I can use



df.groupby('group').agg("group_color": "first", "val1": "mean", "val2": "mean")

group_color val1 val2
group
A green 3.333333 4.666667
B blue 4.500000 6.000000


but that does not work when the data frame in question has more value columns (val3, val4 etc.).
Is there a way to dynamically take the mean of "all the other columns" or "all columns containing val in their names"?










share|improve this question



























  • is group_color always the same for one group?

    – Quang Hoang
    Sep 18 at 13:56











  • @QuangHoang: yes, that is the case, but I would still like to retain it

    – MartijnVanAttekum
    Sep 18 at 14:02













22













22









22


3






I have a script that generates a pandas data frame with a varying number of value columns. As an example, this df might be



import pandas as pd
df = pd.DataFrame(
'group': ['A', 'A', 'A', 'B', 'B'],
'group_color' : ['green', 'green', 'green', 'blue', 'blue'],
'val1': [5, 2, 3, 4, 5],
'val2' : [4, 2, 8, 5, 7]
)

group group_color val1 val2
0 A green 5 4
1 A green 2 2
2 A green 3 8
3 B blue 4 5
4 B blue 5 7


My goal is to get the grouped mean for each of the value columns. In this specific case (with 2 value columns), I can use



df.groupby('group').agg("group_color": "first", "val1": "mean", "val2": "mean")

group_color val1 val2
group
A green 3.333333 4.666667
B blue 4.500000 6.000000


but that does not work when the data frame in question has more value columns (val3, val4 etc.).
Is there a way to dynamically take the mean of "all the other columns" or "all columns containing val in their names"?










share|improve this question
















I have a script that generates a pandas data frame with a varying number of value columns. As an example, this df might be



import pandas as pd
df = pd.DataFrame(
'group': ['A', 'A', 'A', 'B', 'B'],
'group_color' : ['green', 'green', 'green', 'blue', 'blue'],
'val1': [5, 2, 3, 4, 5],
'val2' : [4, 2, 8, 5, 7]
)

group group_color val1 val2
0 A green 5 4
1 A green 2 2
2 A green 3 8
3 B blue 4 5
4 B blue 5 7


My goal is to get the grouped mean for each of the value columns. In this specific case (with 2 value columns), I can use



df.groupby('group').agg("group_color": "first", "val1": "mean", "val2": "mean")

group_color val1 val2
group
A green 3.333333 4.666667
B blue 4.500000 6.000000


but that does not work when the data frame in question has more value columns (val3, val4 etc.).
Is there a way to dynamically take the mean of "all the other columns" or "all columns containing val in their names"?







python pandas aggregate pandas-groupby






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 18 at 23:16









John Conde

193k85 gold badges388 silver badges440 bronze badges




193k85 gold badges388 silver badges440 bronze badges










asked Sep 18 at 13:48









MartijnVanAttekumMartijnVanAttekum

1,0544 silver badges14 bronze badges




1,0544 silver badges14 bronze badges















  • is group_color always the same for one group?

    – Quang Hoang
    Sep 18 at 13:56











  • @QuangHoang: yes, that is the case, but I would still like to retain it

    – MartijnVanAttekum
    Sep 18 at 14:02

















  • is group_color always the same for one group?

    – Quang Hoang
    Sep 18 at 13:56











  • @QuangHoang: yes, that is the case, but I would still like to retain it

    – MartijnVanAttekum
    Sep 18 at 14:02
















is group_color always the same for one group?

– Quang Hoang
Sep 18 at 13:56





is group_color always the same for one group?

– Quang Hoang
Sep 18 at 13:56













@QuangHoang: yes, that is the case, but I would still like to retain it

– MartijnVanAttekum
Sep 18 at 14:02





@QuangHoang: yes, that is the case, but I would still like to retain it

– MartijnVanAttekum
Sep 18 at 14:02












5 Answers
5






active

oldest

votes


















14



















More easy like



df.groupby('group').agg(lambda x : x.head(1) if x.dtype=='object' else x.mean())
Out[63]:
group_color val1 val2
group
A green 3.333333 4.666667
B blue 4.500000 6.000000





share|improve this answer


























  • nice solution! Can you explain why the dtype of the non-numeric columns is object?

    – MartijnVanAttekum
    Sep 18 at 15:20











  • @MartijnVanAttekum this is a dtype in panda, string and others all classified as object

    – WeNYoBen
    Sep 18 at 15:26


















7



















If your group_color is always the same within one group, you can do:



df.pivot_table(index=['group','group_color'],aggfunc='mean')


Output:



 val1 val2
group group_color
A green 3.333333 4.666667
B blue 4.500000 6.000000


In the other case, you can build the dictionary and pass it to agg:



agg_dict = f: 'first' if f=='group_color' else 'mean' for f in df.columns[1:]
df.groupby('group').agg(agg_dict)


Which output:



 group_color val1 val2
group
A green 3.333333 4.666667
B blue 4.500000 6.000000





share|improve this answer





















  • 1





    You're pivot_table answer is the way to go. I used almost the same thing but added a reset_index.

    – piRSquared
    Sep 18 at 16:59


















6



















Unfortunately you will have to apply both aggregation functions separately (that or repeat "valn": "mean" as many times as valx columns). Groupby.agg can take a dictionary but the keys must be individual columns.



The way I'd do this is using DataFrame.filter to select the subset of the dataframe with the columns following the format of valx, aggregate with the mean, and then assign new columns with the aggregated results on the other columns:



(df.filter(regex=r'^val').groupby(df.group).mean()
.assign(color = df.group_color.groupby(df.group).first()))

val1 val2 color
group
A 3.333333 4.666667 green
B 4.500000 6.000000 blue





share|improve this answer



































    4



















    Per OP's comment



    enter image description here



    We can group by both 'group' and 'group_color' without the risk of there being more than one unique 'group_color' per 'group'



    Consequently:



    df.groupby(['group', 'group_color']).mean().reset_index(level=1)

    group_color val1 val2
    group
    A green 3.333333 4.666667
    B blue 4.500000 6.000000





    share|improve this answer

































      1



















      You can go with 2 dictionaries that you can combine like this:



      df.groupby('group').agg(**'group_color': 'first', **c: 'mean' for c in df.columns if c.startswith('val'))


      In this case you have one dict with fixed aggregations and other with dynamic column selection.






      share|improve this answer



























        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );














        draft saved

        draft discarded
















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57994290%2fpandas-aggregate-with-dynamic-column-names%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown


























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        14



















        More easy like



        df.groupby('group').agg(lambda x : x.head(1) if x.dtype=='object' else x.mean())
        Out[63]:
        group_color val1 val2
        group
        A green 3.333333 4.666667
        B blue 4.500000 6.000000





        share|improve this answer


























        • nice solution! Can you explain why the dtype of the non-numeric columns is object?

          – MartijnVanAttekum
          Sep 18 at 15:20











        • @MartijnVanAttekum this is a dtype in panda, string and others all classified as object

          – WeNYoBen
          Sep 18 at 15:26















        14



















        More easy like



        df.groupby('group').agg(lambda x : x.head(1) if x.dtype=='object' else x.mean())
        Out[63]:
        group_color val1 val2
        group
        A green 3.333333 4.666667
        B blue 4.500000 6.000000





        share|improve this answer


























        • nice solution! Can you explain why the dtype of the non-numeric columns is object?

          – MartijnVanAttekum
          Sep 18 at 15:20











        • @MartijnVanAttekum this is a dtype in panda, string and others all classified as object

          – WeNYoBen
          Sep 18 at 15:26













        14















        14











        14









        More easy like



        df.groupby('group').agg(lambda x : x.head(1) if x.dtype=='object' else x.mean())
        Out[63]:
        group_color val1 val2
        group
        A green 3.333333 4.666667
        B blue 4.500000 6.000000





        share|improve this answer














        More easy like



        df.groupby('group').agg(lambda x : x.head(1) if x.dtype=='object' else x.mean())
        Out[63]:
        group_color val1 val2
        group
        A green 3.333333 4.666667
        B blue 4.500000 6.000000






        share|improve this answer













        share|improve this answer




        share|improve this answer










        answered Sep 18 at 14:00









        WeNYoBenWeNYoBen

        169k11 gold badges62 silver badges96 bronze badges




        169k11 gold badges62 silver badges96 bronze badges















        • nice solution! Can you explain why the dtype of the non-numeric columns is object?

          – MartijnVanAttekum
          Sep 18 at 15:20











        • @MartijnVanAttekum this is a dtype in panda, string and others all classified as object

          – WeNYoBen
          Sep 18 at 15:26

















        • nice solution! Can you explain why the dtype of the non-numeric columns is object?

          – MartijnVanAttekum
          Sep 18 at 15:20











        • @MartijnVanAttekum this is a dtype in panda, string and others all classified as object

          – WeNYoBen
          Sep 18 at 15:26
















        nice solution! Can you explain why the dtype of the non-numeric columns is object?

        – MartijnVanAttekum
        Sep 18 at 15:20





        nice solution! Can you explain why the dtype of the non-numeric columns is object?

        – MartijnVanAttekum
        Sep 18 at 15:20













        @MartijnVanAttekum this is a dtype in panda, string and others all classified as object

        – WeNYoBen
        Sep 18 at 15:26





        @MartijnVanAttekum this is a dtype in panda, string and others all classified as object

        – WeNYoBen
        Sep 18 at 15:26













        7



















        If your group_color is always the same within one group, you can do:



        df.pivot_table(index=['group','group_color'],aggfunc='mean')


        Output:



         val1 val2
        group group_color
        A green 3.333333 4.666667
        B blue 4.500000 6.000000


        In the other case, you can build the dictionary and pass it to agg:



        agg_dict = f: 'first' if f=='group_color' else 'mean' for f in df.columns[1:]
        df.groupby('group').agg(agg_dict)


        Which output:



         group_color val1 val2
        group
        A green 3.333333 4.666667
        B blue 4.500000 6.000000





        share|improve this answer





















        • 1





          You're pivot_table answer is the way to go. I used almost the same thing but added a reset_index.

          – piRSquared
          Sep 18 at 16:59















        7



















        If your group_color is always the same within one group, you can do:



        df.pivot_table(index=['group','group_color'],aggfunc='mean')


        Output:



         val1 val2
        group group_color
        A green 3.333333 4.666667
        B blue 4.500000 6.000000


        In the other case, you can build the dictionary and pass it to agg:



        agg_dict = f: 'first' if f=='group_color' else 'mean' for f in df.columns[1:]
        df.groupby('group').agg(agg_dict)


        Which output:



         group_color val1 val2
        group
        A green 3.333333 4.666667
        B blue 4.500000 6.000000





        share|improve this answer





















        • 1





          You're pivot_table answer is the way to go. I used almost the same thing but added a reset_index.

          – piRSquared
          Sep 18 at 16:59













        7















        7











        7









        If your group_color is always the same within one group, you can do:



        df.pivot_table(index=['group','group_color'],aggfunc='mean')


        Output:



         val1 val2
        group group_color
        A green 3.333333 4.666667
        B blue 4.500000 6.000000


        In the other case, you can build the dictionary and pass it to agg:



        agg_dict = f: 'first' if f=='group_color' else 'mean' for f in df.columns[1:]
        df.groupby('group').agg(agg_dict)


        Which output:



         group_color val1 val2
        group
        A green 3.333333 4.666667
        B blue 4.500000 6.000000





        share|improve this answer














        If your group_color is always the same within one group, you can do:



        df.pivot_table(index=['group','group_color'],aggfunc='mean')


        Output:



         val1 val2
        group group_color
        A green 3.333333 4.666667
        B blue 4.500000 6.000000


        In the other case, you can build the dictionary and pass it to agg:



        agg_dict = f: 'first' if f=='group_color' else 'mean' for f in df.columns[1:]
        df.groupby('group').agg(agg_dict)


        Which output:



         group_color val1 val2
        group
        A green 3.333333 4.666667
        B blue 4.500000 6.000000






        share|improve this answer













        share|improve this answer




        share|improve this answer










        answered Sep 18 at 14:00









        Quang HoangQuang Hoang

        27.7k5 gold badges19 silver badges32 bronze badges




        27.7k5 gold badges19 silver badges32 bronze badges










        • 1





          You're pivot_table answer is the way to go. I used almost the same thing but added a reset_index.

          – piRSquared
          Sep 18 at 16:59












        • 1





          You're pivot_table answer is the way to go. I used almost the same thing but added a reset_index.

          – piRSquared
          Sep 18 at 16:59







        1




        1





        You're pivot_table answer is the way to go. I used almost the same thing but added a reset_index.

        – piRSquared
        Sep 18 at 16:59





        You're pivot_table answer is the way to go. I used almost the same thing but added a reset_index.

        – piRSquared
        Sep 18 at 16:59











        6



















        Unfortunately you will have to apply both aggregation functions separately (that or repeat "valn": "mean" as many times as valx columns). Groupby.agg can take a dictionary but the keys must be individual columns.



        The way I'd do this is using DataFrame.filter to select the subset of the dataframe with the columns following the format of valx, aggregate with the mean, and then assign new columns with the aggregated results on the other columns:



        (df.filter(regex=r'^val').groupby(df.group).mean()
        .assign(color = df.group_color.groupby(df.group).first()))

        val1 val2 color
        group
        A 3.333333 4.666667 green
        B 4.500000 6.000000 blue





        share|improve this answer
































          6



















          Unfortunately you will have to apply both aggregation functions separately (that or repeat "valn": "mean" as many times as valx columns). Groupby.agg can take a dictionary but the keys must be individual columns.



          The way I'd do this is using DataFrame.filter to select the subset of the dataframe with the columns following the format of valx, aggregate with the mean, and then assign new columns with the aggregated results on the other columns:



          (df.filter(regex=r'^val').groupby(df.group).mean()
          .assign(color = df.group_color.groupby(df.group).first()))

          val1 val2 color
          group
          A 3.333333 4.666667 green
          B 4.500000 6.000000 blue





          share|improve this answer






























            6















            6











            6









            Unfortunately you will have to apply both aggregation functions separately (that or repeat "valn": "mean" as many times as valx columns). Groupby.agg can take a dictionary but the keys must be individual columns.



            The way I'd do this is using DataFrame.filter to select the subset of the dataframe with the columns following the format of valx, aggregate with the mean, and then assign new columns with the aggregated results on the other columns:



            (df.filter(regex=r'^val').groupby(df.group).mean()
            .assign(color = df.group_color.groupby(df.group).first()))

            val1 val2 color
            group
            A 3.333333 4.666667 green
            B 4.500000 6.000000 blue





            share|improve this answer
















            Unfortunately you will have to apply both aggregation functions separately (that or repeat "valn": "mean" as many times as valx columns). Groupby.agg can take a dictionary but the keys must be individual columns.



            The way I'd do this is using DataFrame.filter to select the subset of the dataframe with the columns following the format of valx, aggregate with the mean, and then assign new columns with the aggregated results on the other columns:



            (df.filter(regex=r'^val').groupby(df.group).mean()
            .assign(color = df.group_color.groupby(df.group).first()))

            val1 val2 color
            group
            A 3.333333 4.666667 green
            B 4.500000 6.000000 blue






            share|improve this answer















            share|improve this answer




            share|improve this answer








            edited Sep 18 at 14:04

























            answered Sep 18 at 13:53









            yatuyatu

            38.7k6 gold badges29 silver badges61 bronze badges




            38.7k6 gold badges29 silver badges61 bronze badges
























                4



















                Per OP's comment



                enter image description here



                We can group by both 'group' and 'group_color' without the risk of there being more than one unique 'group_color' per 'group'



                Consequently:



                df.groupby(['group', 'group_color']).mean().reset_index(level=1)

                group_color val1 val2
                group
                A green 3.333333 4.666667
                B blue 4.500000 6.000000





                share|improve this answer






























                  4



















                  Per OP's comment



                  enter image description here



                  We can group by both 'group' and 'group_color' without the risk of there being more than one unique 'group_color' per 'group'



                  Consequently:



                  df.groupby(['group', 'group_color']).mean().reset_index(level=1)

                  group_color val1 val2
                  group
                  A green 3.333333 4.666667
                  B blue 4.500000 6.000000





                  share|improve this answer




























                    4















                    4











                    4









                    Per OP's comment



                    enter image description here



                    We can group by both 'group' and 'group_color' without the risk of there being more than one unique 'group_color' per 'group'



                    Consequently:



                    df.groupby(['group', 'group_color']).mean().reset_index(level=1)

                    group_color val1 val2
                    group
                    A green 3.333333 4.666667
                    B blue 4.500000 6.000000





                    share|improve this answer














                    Per OP's comment



                    enter image description here



                    We can group by both 'group' and 'group_color' without the risk of there being more than one unique 'group_color' per 'group'



                    Consequently:



                    df.groupby(['group', 'group_color']).mean().reset_index(level=1)

                    group_color val1 val2
                    group
                    A green 3.333333 4.666667
                    B blue 4.500000 6.000000






                    share|improve this answer













                    share|improve this answer




                    share|improve this answer










                    answered Sep 18 at 16:54









                    piRSquaredpiRSquared

                    190k27 gold badges207 silver badges366 bronze badges




                    190k27 gold badges207 silver badges366 bronze badges
























                        1



















                        You can go with 2 dictionaries that you can combine like this:



                        df.groupby('group').agg(**'group_color': 'first', **c: 'mean' for c in df.columns if c.startswith('val'))


                        In this case you have one dict with fixed aggregations and other with dynamic column selection.






                        share|improve this answer






























                          1



















                          You can go with 2 dictionaries that you can combine like this:



                          df.groupby('group').agg(**'group_color': 'first', **c: 'mean' for c in df.columns if c.startswith('val'))


                          In this case you have one dict with fixed aggregations and other with dynamic column selection.






                          share|improve this answer




























                            1















                            1











                            1









                            You can go with 2 dictionaries that you can combine like this:



                            df.groupby('group').agg(**'group_color': 'first', **c: 'mean' for c in df.columns if c.startswith('val'))


                            In this case you have one dict with fixed aggregations and other with dynamic column selection.






                            share|improve this answer














                            You can go with 2 dictionaries that you can combine like this:



                            df.groupby('group').agg(**'group_color': 'first', **c: 'mean' for c in df.columns if c.startswith('val'))


                            In this case you have one dict with fixed aggregations and other with dynamic column selection.







                            share|improve this answer













                            share|improve this answer




                            share|improve this answer










                            answered Sep 18 at 14:07









                            zipazipa

                            19.8k5 gold badges19 silver badges39 bronze badges




                            19.8k5 gold badges19 silver badges39 bronze badges































                                draft saved

                                draft discarded















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57994290%2fpandas-aggregate-with-dynamic-column-names%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown









                                Popular posts from this blog

                                Tamil (spriik) Luke uk diar | Nawigatjuun

                                Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                                Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?