How to return timedelta groupby by particular columnHow to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory?How to get the current time in PythonHow can I make a time delay in Python?How do I sort a dictionary by value?How to make a chain of function decorators?How to make a flat list out of list of listsHow do I list all files of a directory?

Cauchy reals and Dedekind reals satisfy "the same mathematical theorems"

What is this called? A tube flange bearing threaded for threaded pushrod

Should I be able to keep my company purchased standing desk when I leave my job?

Will it hurt my career to work as a graphic designer in a startup for beauty and skin care?

Why should I cook the flour first when making bechamel sauce?

Can a Resident Assistant Be Told to Ignore a Lawful Order?

I have accepted an internship offer. Should I inform companies I have applied to that have not gotten back to me yet?

Extension of trace on von Neumann subalgebra

Was all the fuel expended in each stage of a Saturn V launch?

Can I send medicine to an American visitor in Canada?

Can a polymorphed creature understand languages spoken under the effect of Tongues?

Is there an English equivalent for "Les carottes sont cuites", while keeping the vegetable reference?

What exactly is a Hadouken?

Source of story about the Vilna Gaon and immigration policy

What's the meaning of こそ in this sentence?

If a player tries to persuade somebody, what should that creature roll not to be persuaded?

What alternatives exist to at-will employment?

Video editor for YouTube

How to honestly answer questions from a girlfriend like "How did you find this place" without giving the impression I'm always talking about my exes?

What is the technical explanation of the note "A♭" in a F7 chord in the key of C?

Too many spies!

Is there a good program to play chess online in ubuntu?

What are the arguments for California’s nonpartisan blanket primaries?

Sending a photo of my bank account card to the future employer



How to return timedelta groupby by particular column


How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory?How to get the current time in PythonHow can I make a time delay in Python?How do I sort a dictionary by value?How to make a chain of function decorators?How to make a flat list out of list of listsHow do I list all files of a directory?






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








0















I have written some code to calculate the time it takes to complete each milestone in a particular project (by subtracting the previous endtime from the start date in the following row).



jb_id mlstne_id strt_tme end_tme err_tme max
166 1511 2019-01-31 07:14:43 2019-01-31 08:36:07 NaT NaN
166 1515 2019-01-31 08:36:07 2019-01-31 08:38:26 NaT 0.0
166 1518 2019-01-31 12:16:46 NaT 2019-01-31 13:18:40 218.0
166 1520 2019-01-31 13:21:27 2019-01-31 13:30:20 NaT 2.0
166 1524 2019-01-31 13:30:21 2019-01-31 13:34:49 2019-01-31 13:34:49 0.0
167 1530 2019-01-31 13:35:49 2019-01-31 13:36:49 NaT 1.0


Max start returns the largest time delta (between subtracting the previous end time from the current row's start time and subtracting the previous err_time from the current row's start time). So looking at the above example, since 167 is a new jb_id the max time should not be one minute, it should be NaT because this is the start of a new job



testing = time.sort_values(['jb_id','mlstne_id'], ascending=[True,True])
testing['start1'] = (testing['strt_tme'] - testing['end_tme'].shift(1)).apply(lambda x: x.total_seconds()//60)
testing['start2'] = (testing['strt_tme'] - testing['err_tme'].shift(1)).apply(lambda x: x.total_seconds()//60)
testing['max'] = testing[['start1','start2']].max(axis=1)


The problem I am having is that each milestone is tied to a specific project, with a project id column denoting which project the milestone belongs to. When I apply my code to the entire dataframe the first mlstne_id for each new project returns max minutes that is a time delta of the previous jb_id's last project end time and the new jb_id's start time as opposed to returning NaN (because this is a new job).



I suspect the solution may involve using groupby and then finding the timedeltas groupby by the jb_id?










share|improve this question






























    0















    I have written some code to calculate the time it takes to complete each milestone in a particular project (by subtracting the previous endtime from the start date in the following row).



    jb_id mlstne_id strt_tme end_tme err_tme max
    166 1511 2019-01-31 07:14:43 2019-01-31 08:36:07 NaT NaN
    166 1515 2019-01-31 08:36:07 2019-01-31 08:38:26 NaT 0.0
    166 1518 2019-01-31 12:16:46 NaT 2019-01-31 13:18:40 218.0
    166 1520 2019-01-31 13:21:27 2019-01-31 13:30:20 NaT 2.0
    166 1524 2019-01-31 13:30:21 2019-01-31 13:34:49 2019-01-31 13:34:49 0.0
    167 1530 2019-01-31 13:35:49 2019-01-31 13:36:49 NaT 1.0


    Max start returns the largest time delta (between subtracting the previous end time from the current row's start time and subtracting the previous err_time from the current row's start time). So looking at the above example, since 167 is a new jb_id the max time should not be one minute, it should be NaT because this is the start of a new job



    testing = time.sort_values(['jb_id','mlstne_id'], ascending=[True,True])
    testing['start1'] = (testing['strt_tme'] - testing['end_tme'].shift(1)).apply(lambda x: x.total_seconds()//60)
    testing['start2'] = (testing['strt_tme'] - testing['err_tme'].shift(1)).apply(lambda x: x.total_seconds()//60)
    testing['max'] = testing[['start1','start2']].max(axis=1)


    The problem I am having is that each milestone is tied to a specific project, with a project id column denoting which project the milestone belongs to. When I apply my code to the entire dataframe the first mlstne_id for each new project returns max minutes that is a time delta of the previous jb_id's last project end time and the new jb_id's start time as opposed to returning NaN (because this is a new job).



    I suspect the solution may involve using groupby and then finding the timedeltas groupby by the jb_id?










    share|improve this question


























      0












      0








      0








      I have written some code to calculate the time it takes to complete each milestone in a particular project (by subtracting the previous endtime from the start date in the following row).



      jb_id mlstne_id strt_tme end_tme err_tme max
      166 1511 2019-01-31 07:14:43 2019-01-31 08:36:07 NaT NaN
      166 1515 2019-01-31 08:36:07 2019-01-31 08:38:26 NaT 0.0
      166 1518 2019-01-31 12:16:46 NaT 2019-01-31 13:18:40 218.0
      166 1520 2019-01-31 13:21:27 2019-01-31 13:30:20 NaT 2.0
      166 1524 2019-01-31 13:30:21 2019-01-31 13:34:49 2019-01-31 13:34:49 0.0
      167 1530 2019-01-31 13:35:49 2019-01-31 13:36:49 NaT 1.0


      Max start returns the largest time delta (between subtracting the previous end time from the current row's start time and subtracting the previous err_time from the current row's start time). So looking at the above example, since 167 is a new jb_id the max time should not be one minute, it should be NaT because this is the start of a new job



      testing = time.sort_values(['jb_id','mlstne_id'], ascending=[True,True])
      testing['start1'] = (testing['strt_tme'] - testing['end_tme'].shift(1)).apply(lambda x: x.total_seconds()//60)
      testing['start2'] = (testing['strt_tme'] - testing['err_tme'].shift(1)).apply(lambda x: x.total_seconds()//60)
      testing['max'] = testing[['start1','start2']].max(axis=1)


      The problem I am having is that each milestone is tied to a specific project, with a project id column denoting which project the milestone belongs to. When I apply my code to the entire dataframe the first mlstne_id for each new project returns max minutes that is a time delta of the previous jb_id's last project end time and the new jb_id's start time as opposed to returning NaN (because this is a new job).



      I suspect the solution may involve using groupby and then finding the timedeltas groupby by the jb_id?










      share|improve this question
















      I have written some code to calculate the time it takes to complete each milestone in a particular project (by subtracting the previous endtime from the start date in the following row).



      jb_id mlstne_id strt_tme end_tme err_tme max
      166 1511 2019-01-31 07:14:43 2019-01-31 08:36:07 NaT NaN
      166 1515 2019-01-31 08:36:07 2019-01-31 08:38:26 NaT 0.0
      166 1518 2019-01-31 12:16:46 NaT 2019-01-31 13:18:40 218.0
      166 1520 2019-01-31 13:21:27 2019-01-31 13:30:20 NaT 2.0
      166 1524 2019-01-31 13:30:21 2019-01-31 13:34:49 2019-01-31 13:34:49 0.0
      167 1530 2019-01-31 13:35:49 2019-01-31 13:36:49 NaT 1.0


      Max start returns the largest time delta (between subtracting the previous end time from the current row's start time and subtracting the previous err_time from the current row's start time). So looking at the above example, since 167 is a new jb_id the max time should not be one minute, it should be NaT because this is the start of a new job



      testing = time.sort_values(['jb_id','mlstne_id'], ascending=[True,True])
      testing['start1'] = (testing['strt_tme'] - testing['end_tme'].shift(1)).apply(lambda x: x.total_seconds()//60)
      testing['start2'] = (testing['strt_tme'] - testing['err_tme'].shift(1)).apply(lambda x: x.total_seconds()//60)
      testing['max'] = testing[['start1','start2']].max(axis=1)


      The problem I am having is that each milestone is tied to a specific project, with a project id column denoting which project the milestone belongs to. When I apply my code to the entire dataframe the first mlstne_id for each new project returns max minutes that is a time delta of the previous jb_id's last project end time and the new jb_id's start time as opposed to returning NaN (because this is a new job).



      I suspect the solution may involve using groupby and then finding the timedeltas groupby by the jb_id?







      python






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 7:50







      Emm

















      asked Mar 26 at 7:34









      EmmEmm

      3251 silver badge11 bronze badges




      3251 silver badge11 bronze badges






















          0






          active

          oldest

          votes










          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%2f55351885%2fhow-to-return-timedelta-groupby-by-particular-column%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          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%2f55351885%2fhow-to-return-timedelta-groupby-by-particular-column%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

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?