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

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현