how to choose random datetime of two different columns?









up vote
1
down vote

favorite












After some merging data, I have got a dataframe as:



Name Stage Start End

Hulk A1 21/10/2018 06:34:15 21/10/2018 07:34:15
Hulk A4 21/10/2018 07:34:15 21/10/2018 08:34:15
Sam A1 21/10/2018 09:34:15 21/10/2018 10:34:15
Sam A4 21/10/2018 10:34:15 21/10/2018 11:34:15


so I need to arrange these data as follows, in form like start of A1 and end of A4:



Name Stage Start End

Hulk A1,A4 21/10/2018 06:34:15 21/10/2018 08:34:15
Sam A1,A4 21/10/2018 09:34:15 21/10/2018 11:34:15


How this could be acheived ? I am quite new with python and pandas.










share|improve this question









New contributor




Ranjan raghav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    1
    down vote

    favorite












    After some merging data, I have got a dataframe as:



    Name Stage Start End

    Hulk A1 21/10/2018 06:34:15 21/10/2018 07:34:15
    Hulk A4 21/10/2018 07:34:15 21/10/2018 08:34:15
    Sam A1 21/10/2018 09:34:15 21/10/2018 10:34:15
    Sam A4 21/10/2018 10:34:15 21/10/2018 11:34:15


    so I need to arrange these data as follows, in form like start of A1 and end of A4:



    Name Stage Start End

    Hulk A1,A4 21/10/2018 06:34:15 21/10/2018 08:34:15
    Sam A1,A4 21/10/2018 09:34:15 21/10/2018 11:34:15


    How this could be acheived ? I am quite new with python and pandas.










    share|improve this question









    New contributor




    Ranjan raghav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      After some merging data, I have got a dataframe as:



      Name Stage Start End

      Hulk A1 21/10/2018 06:34:15 21/10/2018 07:34:15
      Hulk A4 21/10/2018 07:34:15 21/10/2018 08:34:15
      Sam A1 21/10/2018 09:34:15 21/10/2018 10:34:15
      Sam A4 21/10/2018 10:34:15 21/10/2018 11:34:15


      so I need to arrange these data as follows, in form like start of A1 and end of A4:



      Name Stage Start End

      Hulk A1,A4 21/10/2018 06:34:15 21/10/2018 08:34:15
      Sam A1,A4 21/10/2018 09:34:15 21/10/2018 11:34:15


      How this could be acheived ? I am quite new with python and pandas.










      share|improve this question









      New contributor




      Ranjan raghav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      After some merging data, I have got a dataframe as:



      Name Stage Start End

      Hulk A1 21/10/2018 06:34:15 21/10/2018 07:34:15
      Hulk A4 21/10/2018 07:34:15 21/10/2018 08:34:15
      Sam A1 21/10/2018 09:34:15 21/10/2018 10:34:15
      Sam A4 21/10/2018 10:34:15 21/10/2018 11:34:15


      so I need to arrange these data as follows, in form like start of A1 and end of A4:



      Name Stage Start End

      Hulk A1,A4 21/10/2018 06:34:15 21/10/2018 08:34:15
      Sam A1,A4 21/10/2018 09:34:15 21/10/2018 11:34:15


      How this could be acheived ? I am quite new with python and pandas.







      python-2.7 pandas dataframe slice






      share|improve this question









      New contributor




      Ranjan raghav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Ranjan raghav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 2 days ago









      James Z

      11.1k71735




      11.1k71735






      New contributor




      Ranjan raghav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 days ago









      Ranjan raghav

      153




      153




      New contributor




      Ranjan raghav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Ranjan raghav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Ranjan raghav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Use agg what working with first and last function nice, if for each group are 2 Stage values ordered like in sample data:



          Also join is pure python function.



          df = df.groupby('Name', as_index=False).agg('Stage':', '.join,'Start':'first', 'End':'last')
          print (df)
          Name Stage Start End
          0 Hulk A1, A4 21/10/2018 06:34:15 21/10/2018 08:34:15
          1 Sam A1, A4 21/10/2018 09:34:15 21/10/2018 11:34:15





          share|improve this answer


















          • 1




            thanks for the solution. But in doc of agg under pandas there is no info about join , first , last...How do one learn about it ? @jezrael
            – Ranjan raghav
            2 days ago











          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',
          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
          );



          );






          Ranjan raghav is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238294%2fhow-to-choose-random-datetime-of-two-different-columns%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Use agg what working with first and last function nice, if for each group are 2 Stage values ordered like in sample data:



          Also join is pure python function.



          df = df.groupby('Name', as_index=False).agg('Stage':', '.join,'Start':'first', 'End':'last')
          print (df)
          Name Stage Start End
          0 Hulk A1, A4 21/10/2018 06:34:15 21/10/2018 08:34:15
          1 Sam A1, A4 21/10/2018 09:34:15 21/10/2018 11:34:15





          share|improve this answer


















          • 1




            thanks for the solution. But in doc of agg under pandas there is no info about join , first , last...How do one learn about it ? @jezrael
            – Ranjan raghav
            2 days ago















          up vote
          1
          down vote



          accepted










          Use agg what working with first and last function nice, if for each group are 2 Stage values ordered like in sample data:



          Also join is pure python function.



          df = df.groupby('Name', as_index=False).agg('Stage':', '.join,'Start':'first', 'End':'last')
          print (df)
          Name Stage Start End
          0 Hulk A1, A4 21/10/2018 06:34:15 21/10/2018 08:34:15
          1 Sam A1, A4 21/10/2018 09:34:15 21/10/2018 11:34:15





          share|improve this answer


















          • 1




            thanks for the solution. But in doc of agg under pandas there is no info about join , first , last...How do one learn about it ? @jezrael
            – Ranjan raghav
            2 days ago













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Use agg what working with first and last function nice, if for each group are 2 Stage values ordered like in sample data:



          Also join is pure python function.



          df = df.groupby('Name', as_index=False).agg('Stage':', '.join,'Start':'first', 'End':'last')
          print (df)
          Name Stage Start End
          0 Hulk A1, A4 21/10/2018 06:34:15 21/10/2018 08:34:15
          1 Sam A1, A4 21/10/2018 09:34:15 21/10/2018 11:34:15





          share|improve this answer














          Use agg what working with first and last function nice, if for each group are 2 Stage values ordered like in sample data:



          Also join is pure python function.



          df = df.groupby('Name', as_index=False).agg('Stage':', '.join,'Start':'first', 'End':'last')
          print (df)
          Name Stage Start End
          0 Hulk A1, A4 21/10/2018 06:34:15 21/10/2018 08:34:15
          1 Sam A1, A4 21/10/2018 09:34:15 21/10/2018 11:34:15






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered 2 days ago









          jezrael

          305k20238314




          305k20238314







          • 1




            thanks for the solution. But in doc of agg under pandas there is no info about join , first , last...How do one learn about it ? @jezrael
            – Ranjan raghav
            2 days ago













          • 1




            thanks for the solution. But in doc of agg under pandas there is no info about join , first , last...How do one learn about it ? @jezrael
            – Ranjan raghav
            2 days ago








          1




          1




          thanks for the solution. But in doc of agg under pandas there is no info about join , first , last...How do one learn about it ? @jezrael
          – Ranjan raghav
          2 days ago





          thanks for the solution. But in doc of agg under pandas there is no info about join , first , last...How do one learn about it ? @jezrael
          – Ranjan raghav
          2 days ago











          Ranjan raghav is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          Ranjan raghav is a new contributor. Be nice, and check out our Code of Conduct.












          Ranjan raghav is a new contributor. Be nice, and check out our Code of Conduct.











          Ranjan raghav is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238294%2fhow-to-choose-random-datetime-of-two-different-columns%23new-answer', 'question_page');

          );

          Post as a guest














































































          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          政党

          天津地下鉄3号線