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



























    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

























      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















      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















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 12:14









      James Z

      11.1k71735




      11.1k71735










      asked Nov 10 at 11:03









      Ranjan raghav

      153




      153






















          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
            Nov 10 at 11:15











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



          );













          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















          Required, but never shown

























          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
            Nov 10 at 11:15















          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
            Nov 10 at 11:15













          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 Nov 10 at 11:17

























          answered Nov 10 at 11:10









          jezrael

          313k21250327




          313k21250327







          • 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
            Nov 10 at 11:15













          • 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
            Nov 10 at 11:15








          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
          Nov 10 at 11:15





          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
          Nov 10 at 11:15


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53238294%2fhow-to-choose-random-datetime-of-two-different-columns%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

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo