Merge Python 3 DataFrame rows that share a cell value, putting another value into a comma separated arrayFilter dataframe rows if value in column is in a set list of valuesUse a list of values to select rows from a pandas dataframeHow to drop rows of Pandas DataFrame whose value in certain columns is NaNSet value for particular cell in pandas DataFrame using indexSelect rows from a DataFrame based on values in a column in pandasDeleting DataFrame row in Pandas based on column valueMerging two DataFrames with conditionals to either update column or append rowComplex Dataframe Merge Python PandasMerge dataframes without duplicating rows in python pandasHow to merge 2 DataFrames on specific rows and columns?

Are modes in jazz primarily a melody thing?

Do the Zhentarim fire members for killing fellow members?

How do I minimise waste on a flight?

Is it safe to keep the GPU on 100% utilization for a very long time?

Good introductory book to type theory?

All of my Firefox add-ons have been disabled suddenly, how can I re-enable them?

Which "exotic salt" can lower water's freezing point by 70 °C?

Appropriate age to involve kids in life changing decisions

Convert Numbers To Emoji Math

Was there a dinosaur-counter in the original Jurassic Park movie?

Employee is self-centered and affects the team negatively

How is it believable that Euron could so easily pull off this ambush?

My large rocket is still flipping over

Does restarting the SQL Services (on the machine) clear the server cache (for things like query plans and statistics)?

An adjective or a noun to describe a very small apartment / house etc

What's weird about Proto-Indo-European Stops?

The unknown and unexplained in science fiction

Why can’t you see at the start of the Big Bang?

Why is there a cap on 401k contributions?

Can anyone identify this unknown 1988 PC card from The Palantir Corporation?

call() a function within its own context

Why were the rules for Proliferate changed?

Antivirus for Ubuntu 18.04

What chord could the notes 'F A♭ E♭' form?



Merge Python 3 DataFrame rows that share a cell value, putting another value into a comma separated array


Filter dataframe rows if value in column is in a set list of valuesUse a list of values to select rows from a pandas dataframeHow to drop rows of Pandas DataFrame whose value in certain columns is NaNSet value for particular cell in pandas DataFrame using indexSelect rows from a DataFrame based on values in a column in pandasDeleting DataFrame row in Pandas based on column valueMerging two DataFrames with conditionals to either update column or append rowComplex Dataframe Merge Python PandasMerge dataframes without duplicating rows in python pandasHow to merge 2 DataFrames on specific rows and columns?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I have a Python DataFrame where emails are duplicated. I'd like to find all the duplicates and merge them so that there are an array of account numbers attached to the email. I'd also like to preserve the 3rd column in the merged column.



AccountID Email Quality_3

1 blue@somedomain.com High
2 red@somedomain.com
3 blue@somedomain.com
4 green@somedomain.com Medium
5 blue@somedomain.com
6 red@somedomain.com
7 blue@somedomain.com
8 green@somedomain.com



AccountID Email Quality_3
1, 3, 5, 7 blue@somedomain.com High
2, 6 red@somedomain.com
4, 8 green@somedomain.com Medium


I am looking at left and right joins, but I can't seem to figure it out.










share|improve this question






























    2















    I have a Python DataFrame where emails are duplicated. I'd like to find all the duplicates and merge them so that there are an array of account numbers attached to the email. I'd also like to preserve the 3rd column in the merged column.



    AccountID Email Quality_3

    1 blue@somedomain.com High
    2 red@somedomain.com
    3 blue@somedomain.com
    4 green@somedomain.com Medium
    5 blue@somedomain.com
    6 red@somedomain.com
    7 blue@somedomain.com
    8 green@somedomain.com



    AccountID Email Quality_3
    1, 3, 5, 7 blue@somedomain.com High
    2, 6 red@somedomain.com
    4, 8 green@somedomain.com Medium


    I am looking at left and right joins, but I can't seem to figure it out.










    share|improve this question


























      2












      2








      2








      I have a Python DataFrame where emails are duplicated. I'd like to find all the duplicates and merge them so that there are an array of account numbers attached to the email. I'd also like to preserve the 3rd column in the merged column.



      AccountID Email Quality_3

      1 blue@somedomain.com High
      2 red@somedomain.com
      3 blue@somedomain.com
      4 green@somedomain.com Medium
      5 blue@somedomain.com
      6 red@somedomain.com
      7 blue@somedomain.com
      8 green@somedomain.com



      AccountID Email Quality_3
      1, 3, 5, 7 blue@somedomain.com High
      2, 6 red@somedomain.com
      4, 8 green@somedomain.com Medium


      I am looking at left and right joins, but I can't seem to figure it out.










      share|improve this question
















      I have a Python DataFrame where emails are duplicated. I'd like to find all the duplicates and merge them so that there are an array of account numbers attached to the email. I'd also like to preserve the 3rd column in the merged column.



      AccountID Email Quality_3

      1 blue@somedomain.com High
      2 red@somedomain.com
      3 blue@somedomain.com
      4 green@somedomain.com Medium
      5 blue@somedomain.com
      6 red@somedomain.com
      7 blue@somedomain.com
      8 green@somedomain.com



      AccountID Email Quality_3
      1, 3, 5, 7 blue@somedomain.com High
      2, 6 red@somedomain.com
      4, 8 green@somedomain.com Medium


      I am looking at left and right joins, but I can't seem to figure it out.







      python python-3.x pandas dataframe merge






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 22:13







      NothingToSeeHere

















      asked Mar 23 at 6:16









      NothingToSeeHereNothingToSeeHere

      51921231




      51921231






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Try this:



          df_new=(df.astype(str).groupby('Email')['AccountID','Quality_3']
          .agg('AccountID':lambda x: ','.join(x),'Quality_3':'first').reset_index())
          print(df_new)

          Email AccountID Quality_3
          0 blue@somedomain.com 1,3,5,7 High
          1 green@somedomain.com 4,8 Medium
          2 red@somedomain.com 2,6 None





          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/3.0/"u003ecc by-sa 3.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%2f55311147%2fmerge-python-3-dataframe-rows-that-share-a-cell-value-putting-another-value-int%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Try this:



            df_new=(df.astype(str).groupby('Email')['AccountID','Quality_3']
            .agg('AccountID':lambda x: ','.join(x),'Quality_3':'first').reset_index())
            print(df_new)

            Email AccountID Quality_3
            0 blue@somedomain.com 1,3,5,7 High
            1 green@somedomain.com 4,8 Medium
            2 red@somedomain.com 2,6 None





            share|improve this answer



























              2














              Try this:



              df_new=(df.astype(str).groupby('Email')['AccountID','Quality_3']
              .agg('AccountID':lambda x: ','.join(x),'Quality_3':'first').reset_index())
              print(df_new)

              Email AccountID Quality_3
              0 blue@somedomain.com 1,3,5,7 High
              1 green@somedomain.com 4,8 Medium
              2 red@somedomain.com 2,6 None





              share|improve this answer

























                2












                2








                2







                Try this:



                df_new=(df.astype(str).groupby('Email')['AccountID','Quality_3']
                .agg('AccountID':lambda x: ','.join(x),'Quality_3':'first').reset_index())
                print(df_new)

                Email AccountID Quality_3
                0 blue@somedomain.com 1,3,5,7 High
                1 green@somedomain.com 4,8 Medium
                2 red@somedomain.com 2,6 None





                share|improve this answer













                Try this:



                df_new=(df.astype(str).groupby('Email')['AccountID','Quality_3']
                .agg('AccountID':lambda x: ','.join(x),'Quality_3':'first').reset_index())
                print(df_new)

                Email AccountID Quality_3
                0 blue@somedomain.com 1,3,5,7 High
                1 green@somedomain.com 4,8 Medium
                2 red@somedomain.com 2,6 None






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 23 at 6:23









                anky_91anky_91

                12.5k3922




                12.5k3922





























                    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%2f55311147%2fmerge-python-3-dataframe-rows-that-share-a-cell-value-putting-another-value-int%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript