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

          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권, 지리지 충청도 공주목 은진현