How to create a time threshold based column given a time gap?











up vote
1
down vote

favorite












I have a pandas dataframe with several columns, however for visual purposes consider the columns Id and timestamp. As you can see the pandas dataframe is sorted by Id column.



Id                timestamp

11 2018-10-19 13:00:00
11 2018-10-19 13:05:00
11 2018-10-19 13:06:00
11 2018-10-19 13:07:00
11 2018-10-19 13:30:00
11 2018-10-19 13:31:00
11 2018-10-19 13:32:00
11 2018-10-19 13:55:00
11 2018-10-19 13:54:00
11 2018-10-21 20:47:09
11 2018-10-21 20:48:27
11 2018-10-21 20:48:45
11 2018-10-21 20:48:52
12 2018-10-09 20:30:46
12 2018-10-09 20:30:22
12 2018-10-09 20:30:05
12 2018-10-09 20:29:44
12 2018-10-09 20:29:31
13 2018-10-19 18:49:08
13 2018-10-19 18:49:13
13 2018-10-11 18:46:15
14 2018-10-11 10:46:40
14 2018-10-23 10:39:52


How can create create another ID column based on 10 minutes time gaps? That is for every timestamp 10 minutes threshold create a new different `ID_2:



Id                timestamp            ID_2

11 2018-10-19 13:00:00 01
11 2018-10-19 13:05:00 01
11 2018-10-19 13:06:00 01
11 2018-10-19 13:07:00 01
11 2018-10-19 13:30:00 02
11 2018-10-19 13:31:00 02
11 2018-10-19 13:32:00 02
11 2018-10-19 13:55:00 03
11 2018-10-19 13:54:00 03
11 2018-10-21 20:47:09 04
11 2018-10-21 20:48:27 04
11 2018-10-21 20:48:45 04
11 2018-10-21 20:48:52 04
12 2018-10-09 20:30:46 04
12 2018-10-09 20:30:22 04
12 2018-10-09 20:30:05 04
12 2018-10-09 20:29:44 05
12 2018-10-09 20:29:31 05
13 2018-10-19 18:49:08 06
13 2018-10-19 18:49:13 06
13 2018-10-11 18:46:15 07
14 2018-10-11 10:46:40 07


I tried to detect the time gaps as follows:



df['col_new'] = (df['timestamp'].diff()).dt.seconds > 600


However, I do not understand how to apply a backward fill in order to create the IDs. Therefore, how can I detect time gaps and assign them a new id?










share|improve this question


























    up vote
    1
    down vote

    favorite












    I have a pandas dataframe with several columns, however for visual purposes consider the columns Id and timestamp. As you can see the pandas dataframe is sorted by Id column.



    Id                timestamp

    11 2018-10-19 13:00:00
    11 2018-10-19 13:05:00
    11 2018-10-19 13:06:00
    11 2018-10-19 13:07:00
    11 2018-10-19 13:30:00
    11 2018-10-19 13:31:00
    11 2018-10-19 13:32:00
    11 2018-10-19 13:55:00
    11 2018-10-19 13:54:00
    11 2018-10-21 20:47:09
    11 2018-10-21 20:48:27
    11 2018-10-21 20:48:45
    11 2018-10-21 20:48:52
    12 2018-10-09 20:30:46
    12 2018-10-09 20:30:22
    12 2018-10-09 20:30:05
    12 2018-10-09 20:29:44
    12 2018-10-09 20:29:31
    13 2018-10-19 18:49:08
    13 2018-10-19 18:49:13
    13 2018-10-11 18:46:15
    14 2018-10-11 10:46:40
    14 2018-10-23 10:39:52


    How can create create another ID column based on 10 minutes time gaps? That is for every timestamp 10 minutes threshold create a new different `ID_2:



    Id                timestamp            ID_2

    11 2018-10-19 13:00:00 01
    11 2018-10-19 13:05:00 01
    11 2018-10-19 13:06:00 01
    11 2018-10-19 13:07:00 01
    11 2018-10-19 13:30:00 02
    11 2018-10-19 13:31:00 02
    11 2018-10-19 13:32:00 02
    11 2018-10-19 13:55:00 03
    11 2018-10-19 13:54:00 03
    11 2018-10-21 20:47:09 04
    11 2018-10-21 20:48:27 04
    11 2018-10-21 20:48:45 04
    11 2018-10-21 20:48:52 04
    12 2018-10-09 20:30:46 04
    12 2018-10-09 20:30:22 04
    12 2018-10-09 20:30:05 04
    12 2018-10-09 20:29:44 05
    12 2018-10-09 20:29:31 05
    13 2018-10-19 18:49:08 06
    13 2018-10-19 18:49:13 06
    13 2018-10-11 18:46:15 07
    14 2018-10-11 10:46:40 07


    I tried to detect the time gaps as follows:



    df['col_new'] = (df['timestamp'].diff()).dt.seconds > 600


    However, I do not understand how to apply a backward fill in order to create the IDs. Therefore, how can I detect time gaps and assign them a new id?










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a pandas dataframe with several columns, however for visual purposes consider the columns Id and timestamp. As you can see the pandas dataframe is sorted by Id column.



      Id                timestamp

      11 2018-10-19 13:00:00
      11 2018-10-19 13:05:00
      11 2018-10-19 13:06:00
      11 2018-10-19 13:07:00
      11 2018-10-19 13:30:00
      11 2018-10-19 13:31:00
      11 2018-10-19 13:32:00
      11 2018-10-19 13:55:00
      11 2018-10-19 13:54:00
      11 2018-10-21 20:47:09
      11 2018-10-21 20:48:27
      11 2018-10-21 20:48:45
      11 2018-10-21 20:48:52
      12 2018-10-09 20:30:46
      12 2018-10-09 20:30:22
      12 2018-10-09 20:30:05
      12 2018-10-09 20:29:44
      12 2018-10-09 20:29:31
      13 2018-10-19 18:49:08
      13 2018-10-19 18:49:13
      13 2018-10-11 18:46:15
      14 2018-10-11 10:46:40
      14 2018-10-23 10:39:52


      How can create create another ID column based on 10 minutes time gaps? That is for every timestamp 10 minutes threshold create a new different `ID_2:



      Id                timestamp            ID_2

      11 2018-10-19 13:00:00 01
      11 2018-10-19 13:05:00 01
      11 2018-10-19 13:06:00 01
      11 2018-10-19 13:07:00 01
      11 2018-10-19 13:30:00 02
      11 2018-10-19 13:31:00 02
      11 2018-10-19 13:32:00 02
      11 2018-10-19 13:55:00 03
      11 2018-10-19 13:54:00 03
      11 2018-10-21 20:47:09 04
      11 2018-10-21 20:48:27 04
      11 2018-10-21 20:48:45 04
      11 2018-10-21 20:48:52 04
      12 2018-10-09 20:30:46 04
      12 2018-10-09 20:30:22 04
      12 2018-10-09 20:30:05 04
      12 2018-10-09 20:29:44 05
      12 2018-10-09 20:29:31 05
      13 2018-10-19 18:49:08 06
      13 2018-10-19 18:49:13 06
      13 2018-10-11 18:46:15 07
      14 2018-10-11 10:46:40 07


      I tried to detect the time gaps as follows:



      df['col_new'] = (df['timestamp'].diff()).dt.seconds > 600


      However, I do not understand how to apply a backward fill in order to create the IDs. Therefore, how can I detect time gaps and assign them a new id?










      share|improve this question













      I have a pandas dataframe with several columns, however for visual purposes consider the columns Id and timestamp. As you can see the pandas dataframe is sorted by Id column.



      Id                timestamp

      11 2018-10-19 13:00:00
      11 2018-10-19 13:05:00
      11 2018-10-19 13:06:00
      11 2018-10-19 13:07:00
      11 2018-10-19 13:30:00
      11 2018-10-19 13:31:00
      11 2018-10-19 13:32:00
      11 2018-10-19 13:55:00
      11 2018-10-19 13:54:00
      11 2018-10-21 20:47:09
      11 2018-10-21 20:48:27
      11 2018-10-21 20:48:45
      11 2018-10-21 20:48:52
      12 2018-10-09 20:30:46
      12 2018-10-09 20:30:22
      12 2018-10-09 20:30:05
      12 2018-10-09 20:29:44
      12 2018-10-09 20:29:31
      13 2018-10-19 18:49:08
      13 2018-10-19 18:49:13
      13 2018-10-11 18:46:15
      14 2018-10-11 10:46:40
      14 2018-10-23 10:39:52


      How can create create another ID column based on 10 minutes time gaps? That is for every timestamp 10 minutes threshold create a new different `ID_2:



      Id                timestamp            ID_2

      11 2018-10-19 13:00:00 01
      11 2018-10-19 13:05:00 01
      11 2018-10-19 13:06:00 01
      11 2018-10-19 13:07:00 01
      11 2018-10-19 13:30:00 02
      11 2018-10-19 13:31:00 02
      11 2018-10-19 13:32:00 02
      11 2018-10-19 13:55:00 03
      11 2018-10-19 13:54:00 03
      11 2018-10-21 20:47:09 04
      11 2018-10-21 20:48:27 04
      11 2018-10-21 20:48:45 04
      11 2018-10-21 20:48:52 04
      12 2018-10-09 20:30:46 04
      12 2018-10-09 20:30:22 04
      12 2018-10-09 20:30:05 04
      12 2018-10-09 20:29:44 05
      12 2018-10-09 20:29:31 05
      13 2018-10-19 18:49:08 06
      13 2018-10-19 18:49:13 06
      13 2018-10-11 18:46:15 07
      14 2018-10-11 10:46:40 07


      I tried to detect the time gaps as follows:



      df['col_new'] = (df['timestamp'].diff()).dt.seconds > 600


      However, I do not understand how to apply a backward fill in order to create the IDs. Therefore, how can I detect time gaps and assign them a new id?







      python python-3.x pandas datetime






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 9:17









      anon

      1457




      1457
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          I believe you need floor with factorize, last add zfill:



          df['timestamp'] = pd.to_datetime(df['timestamp'])

          a = pd.factorize(df['timestamp'].dt.floor('10Min'))[0] + 1
          df['col_new'] = pd.Series(a, index=df.index).astype(str).str.zfill(2)

          print (df)
          Id timestamp ID_2 col_new
          0 11 2018-10-19 13:00:00 01 01
          1 11 2018-10-19 13:05:00 01 01
          2 11 2018-10-19 13:06:00 01 01
          3 11 2018-10-19 13:07:00 01 01
          4 11 2018-10-19 13:30:00 02 02
          5 11 2018-10-19 13:31:00 02 02
          6 11 2018-10-19 13:32:00 02 02
          7 11 2018-10-19 13:55:00 03 03
          8 11 2018-10-19 13:54:00 03 03
          9 11 2018-10-21 20:47:09 04 04
          10 11 2018-10-21 20:48:27 04 04
          11 11 2018-10-21 20:48:45 04 04
          12 11 2018-10-21 20:48:52 04 04
          13 12 2018-10-09 20:30:46 04 05
          14 12 2018-10-09 20:30:22 04 05
          15 12 2018-10-09 20:30:05 04 05
          16 12 2018-10-09 20:29:44 05 06
          17 12 2018-10-09 20:29:31 05 06
          18 13 2018-10-19 18:49:08 06 07
          19 13 2018-10-19 18:49:13 06 07
          20 13 2018-10-11 18:46:15 07 08
          21 14 2018-10-11 18:46:40 07 08


          Detail:



          print (df['timestamp'].dt.floor('10Min'))
          0 2018-10-19 13:00:00
          1 2018-10-19 13:00:00
          2 2018-10-19 13:00:00
          3 2018-10-19 13:00:00
          4 2018-10-19 13:30:00
          5 2018-10-19 13:30:00
          6 2018-10-19 13:30:00
          7 2018-10-19 13:50:00
          8 2018-10-19 13:50:00
          9 2018-10-21 20:40:00
          10 2018-10-21 20:40:00
          11 2018-10-21 20:40:00
          12 2018-10-21 20:40:00
          13 2018-10-09 20:30:00
          14 2018-10-09 20:30:00
          15 2018-10-09 20:30:00
          16 2018-10-09 20:20:00
          17 2018-10-09 20:20:00
          18 2018-10-19 18:40:00
          19 2018-10-19 18:40:00
          20 2018-10-11 18:40:00
          21 2018-10-11 18:40:00
          Name: timestamp, dtype: datetime64[ns]





          share|improve this answer



















          • 2




            wow, this is superbly elegant
            – Pankaj Joshi
            Nov 7 at 9:48






          • 1




            @PankajJoshi - Thank you.
            – jezrael
            Nov 7 at 9:48











          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%2f53186476%2fhow-to-create-a-time-threshold-based-column-given-a-time-gap%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
          3
          down vote



          accepted










          I believe you need floor with factorize, last add zfill:



          df['timestamp'] = pd.to_datetime(df['timestamp'])

          a = pd.factorize(df['timestamp'].dt.floor('10Min'))[0] + 1
          df['col_new'] = pd.Series(a, index=df.index).astype(str).str.zfill(2)

          print (df)
          Id timestamp ID_2 col_new
          0 11 2018-10-19 13:00:00 01 01
          1 11 2018-10-19 13:05:00 01 01
          2 11 2018-10-19 13:06:00 01 01
          3 11 2018-10-19 13:07:00 01 01
          4 11 2018-10-19 13:30:00 02 02
          5 11 2018-10-19 13:31:00 02 02
          6 11 2018-10-19 13:32:00 02 02
          7 11 2018-10-19 13:55:00 03 03
          8 11 2018-10-19 13:54:00 03 03
          9 11 2018-10-21 20:47:09 04 04
          10 11 2018-10-21 20:48:27 04 04
          11 11 2018-10-21 20:48:45 04 04
          12 11 2018-10-21 20:48:52 04 04
          13 12 2018-10-09 20:30:46 04 05
          14 12 2018-10-09 20:30:22 04 05
          15 12 2018-10-09 20:30:05 04 05
          16 12 2018-10-09 20:29:44 05 06
          17 12 2018-10-09 20:29:31 05 06
          18 13 2018-10-19 18:49:08 06 07
          19 13 2018-10-19 18:49:13 06 07
          20 13 2018-10-11 18:46:15 07 08
          21 14 2018-10-11 18:46:40 07 08


          Detail:



          print (df['timestamp'].dt.floor('10Min'))
          0 2018-10-19 13:00:00
          1 2018-10-19 13:00:00
          2 2018-10-19 13:00:00
          3 2018-10-19 13:00:00
          4 2018-10-19 13:30:00
          5 2018-10-19 13:30:00
          6 2018-10-19 13:30:00
          7 2018-10-19 13:50:00
          8 2018-10-19 13:50:00
          9 2018-10-21 20:40:00
          10 2018-10-21 20:40:00
          11 2018-10-21 20:40:00
          12 2018-10-21 20:40:00
          13 2018-10-09 20:30:00
          14 2018-10-09 20:30:00
          15 2018-10-09 20:30:00
          16 2018-10-09 20:20:00
          17 2018-10-09 20:20:00
          18 2018-10-19 18:40:00
          19 2018-10-19 18:40:00
          20 2018-10-11 18:40:00
          21 2018-10-11 18:40:00
          Name: timestamp, dtype: datetime64[ns]





          share|improve this answer



















          • 2




            wow, this is superbly elegant
            – Pankaj Joshi
            Nov 7 at 9:48






          • 1




            @PankajJoshi - Thank you.
            – jezrael
            Nov 7 at 9:48















          up vote
          3
          down vote



          accepted










          I believe you need floor with factorize, last add zfill:



          df['timestamp'] = pd.to_datetime(df['timestamp'])

          a = pd.factorize(df['timestamp'].dt.floor('10Min'))[0] + 1
          df['col_new'] = pd.Series(a, index=df.index).astype(str).str.zfill(2)

          print (df)
          Id timestamp ID_2 col_new
          0 11 2018-10-19 13:00:00 01 01
          1 11 2018-10-19 13:05:00 01 01
          2 11 2018-10-19 13:06:00 01 01
          3 11 2018-10-19 13:07:00 01 01
          4 11 2018-10-19 13:30:00 02 02
          5 11 2018-10-19 13:31:00 02 02
          6 11 2018-10-19 13:32:00 02 02
          7 11 2018-10-19 13:55:00 03 03
          8 11 2018-10-19 13:54:00 03 03
          9 11 2018-10-21 20:47:09 04 04
          10 11 2018-10-21 20:48:27 04 04
          11 11 2018-10-21 20:48:45 04 04
          12 11 2018-10-21 20:48:52 04 04
          13 12 2018-10-09 20:30:46 04 05
          14 12 2018-10-09 20:30:22 04 05
          15 12 2018-10-09 20:30:05 04 05
          16 12 2018-10-09 20:29:44 05 06
          17 12 2018-10-09 20:29:31 05 06
          18 13 2018-10-19 18:49:08 06 07
          19 13 2018-10-19 18:49:13 06 07
          20 13 2018-10-11 18:46:15 07 08
          21 14 2018-10-11 18:46:40 07 08


          Detail:



          print (df['timestamp'].dt.floor('10Min'))
          0 2018-10-19 13:00:00
          1 2018-10-19 13:00:00
          2 2018-10-19 13:00:00
          3 2018-10-19 13:00:00
          4 2018-10-19 13:30:00
          5 2018-10-19 13:30:00
          6 2018-10-19 13:30:00
          7 2018-10-19 13:50:00
          8 2018-10-19 13:50:00
          9 2018-10-21 20:40:00
          10 2018-10-21 20:40:00
          11 2018-10-21 20:40:00
          12 2018-10-21 20:40:00
          13 2018-10-09 20:30:00
          14 2018-10-09 20:30:00
          15 2018-10-09 20:30:00
          16 2018-10-09 20:20:00
          17 2018-10-09 20:20:00
          18 2018-10-19 18:40:00
          19 2018-10-19 18:40:00
          20 2018-10-11 18:40:00
          21 2018-10-11 18:40:00
          Name: timestamp, dtype: datetime64[ns]





          share|improve this answer



















          • 2




            wow, this is superbly elegant
            – Pankaj Joshi
            Nov 7 at 9:48






          • 1




            @PankajJoshi - Thank you.
            – jezrael
            Nov 7 at 9:48













          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          I believe you need floor with factorize, last add zfill:



          df['timestamp'] = pd.to_datetime(df['timestamp'])

          a = pd.factorize(df['timestamp'].dt.floor('10Min'))[0] + 1
          df['col_new'] = pd.Series(a, index=df.index).astype(str).str.zfill(2)

          print (df)
          Id timestamp ID_2 col_new
          0 11 2018-10-19 13:00:00 01 01
          1 11 2018-10-19 13:05:00 01 01
          2 11 2018-10-19 13:06:00 01 01
          3 11 2018-10-19 13:07:00 01 01
          4 11 2018-10-19 13:30:00 02 02
          5 11 2018-10-19 13:31:00 02 02
          6 11 2018-10-19 13:32:00 02 02
          7 11 2018-10-19 13:55:00 03 03
          8 11 2018-10-19 13:54:00 03 03
          9 11 2018-10-21 20:47:09 04 04
          10 11 2018-10-21 20:48:27 04 04
          11 11 2018-10-21 20:48:45 04 04
          12 11 2018-10-21 20:48:52 04 04
          13 12 2018-10-09 20:30:46 04 05
          14 12 2018-10-09 20:30:22 04 05
          15 12 2018-10-09 20:30:05 04 05
          16 12 2018-10-09 20:29:44 05 06
          17 12 2018-10-09 20:29:31 05 06
          18 13 2018-10-19 18:49:08 06 07
          19 13 2018-10-19 18:49:13 06 07
          20 13 2018-10-11 18:46:15 07 08
          21 14 2018-10-11 18:46:40 07 08


          Detail:



          print (df['timestamp'].dt.floor('10Min'))
          0 2018-10-19 13:00:00
          1 2018-10-19 13:00:00
          2 2018-10-19 13:00:00
          3 2018-10-19 13:00:00
          4 2018-10-19 13:30:00
          5 2018-10-19 13:30:00
          6 2018-10-19 13:30:00
          7 2018-10-19 13:50:00
          8 2018-10-19 13:50:00
          9 2018-10-21 20:40:00
          10 2018-10-21 20:40:00
          11 2018-10-21 20:40:00
          12 2018-10-21 20:40:00
          13 2018-10-09 20:30:00
          14 2018-10-09 20:30:00
          15 2018-10-09 20:30:00
          16 2018-10-09 20:20:00
          17 2018-10-09 20:20:00
          18 2018-10-19 18:40:00
          19 2018-10-19 18:40:00
          20 2018-10-11 18:40:00
          21 2018-10-11 18:40:00
          Name: timestamp, dtype: datetime64[ns]





          share|improve this answer














          I believe you need floor with factorize, last add zfill:



          df['timestamp'] = pd.to_datetime(df['timestamp'])

          a = pd.factorize(df['timestamp'].dt.floor('10Min'))[0] + 1
          df['col_new'] = pd.Series(a, index=df.index).astype(str).str.zfill(2)

          print (df)
          Id timestamp ID_2 col_new
          0 11 2018-10-19 13:00:00 01 01
          1 11 2018-10-19 13:05:00 01 01
          2 11 2018-10-19 13:06:00 01 01
          3 11 2018-10-19 13:07:00 01 01
          4 11 2018-10-19 13:30:00 02 02
          5 11 2018-10-19 13:31:00 02 02
          6 11 2018-10-19 13:32:00 02 02
          7 11 2018-10-19 13:55:00 03 03
          8 11 2018-10-19 13:54:00 03 03
          9 11 2018-10-21 20:47:09 04 04
          10 11 2018-10-21 20:48:27 04 04
          11 11 2018-10-21 20:48:45 04 04
          12 11 2018-10-21 20:48:52 04 04
          13 12 2018-10-09 20:30:46 04 05
          14 12 2018-10-09 20:30:22 04 05
          15 12 2018-10-09 20:30:05 04 05
          16 12 2018-10-09 20:29:44 05 06
          17 12 2018-10-09 20:29:31 05 06
          18 13 2018-10-19 18:49:08 06 07
          19 13 2018-10-19 18:49:13 06 07
          20 13 2018-10-11 18:46:15 07 08
          21 14 2018-10-11 18:46:40 07 08


          Detail:



          print (df['timestamp'].dt.floor('10Min'))
          0 2018-10-19 13:00:00
          1 2018-10-19 13:00:00
          2 2018-10-19 13:00:00
          3 2018-10-19 13:00:00
          4 2018-10-19 13:30:00
          5 2018-10-19 13:30:00
          6 2018-10-19 13:30:00
          7 2018-10-19 13:50:00
          8 2018-10-19 13:50:00
          9 2018-10-21 20:40:00
          10 2018-10-21 20:40:00
          11 2018-10-21 20:40:00
          12 2018-10-21 20:40:00
          13 2018-10-09 20:30:00
          14 2018-10-09 20:30:00
          15 2018-10-09 20:30:00
          16 2018-10-09 20:20:00
          17 2018-10-09 20:20:00
          18 2018-10-19 18:40:00
          19 2018-10-19 18:40:00
          20 2018-10-11 18:40:00
          21 2018-10-11 18:40:00
          Name: timestamp, dtype: datetime64[ns]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 7 at 9:49

























          answered Nov 7 at 9:36









          jezrael

          306k20240316




          306k20240316








          • 2




            wow, this is superbly elegant
            – Pankaj Joshi
            Nov 7 at 9:48






          • 1




            @PankajJoshi - Thank you.
            – jezrael
            Nov 7 at 9:48














          • 2




            wow, this is superbly elegant
            – Pankaj Joshi
            Nov 7 at 9:48






          • 1




            @PankajJoshi - Thank you.
            – jezrael
            Nov 7 at 9:48








          2




          2




          wow, this is superbly elegant
          – Pankaj Joshi
          Nov 7 at 9:48




          wow, this is superbly elegant
          – Pankaj Joshi
          Nov 7 at 9:48




          1




          1




          @PankajJoshi - Thank you.
          – jezrael
          Nov 7 at 9:48




          @PankajJoshi - Thank you.
          – jezrael
          Nov 7 at 9:48


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186476%2fhow-to-create-a-time-threshold-based-column-given-a-time-gap%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







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()