pandas resample starting before the dataset first entry












2















Dear experienced community,
I can't find an elegant solution to my problem.
I have a subsample of my dataset which I want to resample weekly, but starting some weeks before the first entry in my data frame (so a few weeks with 0 counts)



A sample of the data:



In:



print(df_pec.head())


Out:



    Count Image_Sequence_DateTime
18 1 2015-11-06 03:22:19
21 1 2015-11-11 01:48:51
22 1 2015-11-11 07:30:47
37 1 2015-11-25 09:42:23
48 1 2015-12-05 12:12:34


With the earliest image sequence at:



In:



df_pec.Image_Sequence_DateTime.min()


Out:



2015-09-30 15:16:38


I have another function that gives me the starting point of the first week and the last point of the last week ever measured in that experiment, which are:



In:



print(s_startend)


Out:



Start   2015-09-28
End 2017-12-25
dtype: datetime64[ns]


My problem is that I want to resample df_pec weekly, but starting on the very first second of the very first day of the very first week of the experimental deployment.(using s_startend as reference)



I try:



df_pec=df_pec.resample('1W', on='Image_Sequence_DateTime').sum() 
print(df_pec.head(),'n',df_pec.tail())


Out:



                         Count
Image_Sequence_DateTime
2015-10-04 26.0
2015-10-11 92.0
2015-10-18 204.0
2015-10-25 193.0
2015-11-01 187.0
Count
Image_Sequence_DateTime
2017-11-19 20.0
2017-11-26 34.0
2017-12-03 16.0
2017-12-10 11.0
2017-12-17 3.0


This is pretty weird because it is even skipping the first days of data in df_pec.(starting 2015-09-30 15:16:38)



And even if it worked, I have no way of indicating the resampling to start and end in specified values (s_startend from my example), even if there are no records in the earliest and latest weeks in my subsample df_pec.



I thought about artificially adding two entries to df_pec with the real start and real end, but I think it is not so elegant and I don't want to be adding meaningless keys to my df.



Thank you very much for your wisdom!










share|improve this question





























    2















    Dear experienced community,
    I can't find an elegant solution to my problem.
    I have a subsample of my dataset which I want to resample weekly, but starting some weeks before the first entry in my data frame (so a few weeks with 0 counts)



    A sample of the data:



    In:



    print(df_pec.head())


    Out:



        Count Image_Sequence_DateTime
    18 1 2015-11-06 03:22:19
    21 1 2015-11-11 01:48:51
    22 1 2015-11-11 07:30:47
    37 1 2015-11-25 09:42:23
    48 1 2015-12-05 12:12:34


    With the earliest image sequence at:



    In:



    df_pec.Image_Sequence_DateTime.min()


    Out:



    2015-09-30 15:16:38


    I have another function that gives me the starting point of the first week and the last point of the last week ever measured in that experiment, which are:



    In:



    print(s_startend)


    Out:



    Start   2015-09-28
    End 2017-12-25
    dtype: datetime64[ns]


    My problem is that I want to resample df_pec weekly, but starting on the very first second of the very first day of the very first week of the experimental deployment.(using s_startend as reference)



    I try:



    df_pec=df_pec.resample('1W', on='Image_Sequence_DateTime').sum() 
    print(df_pec.head(),'n',df_pec.tail())


    Out:



                             Count
    Image_Sequence_DateTime
    2015-10-04 26.0
    2015-10-11 92.0
    2015-10-18 204.0
    2015-10-25 193.0
    2015-11-01 187.0
    Count
    Image_Sequence_DateTime
    2017-11-19 20.0
    2017-11-26 34.0
    2017-12-03 16.0
    2017-12-10 11.0
    2017-12-17 3.0


    This is pretty weird because it is even skipping the first days of data in df_pec.(starting 2015-09-30 15:16:38)



    And even if it worked, I have no way of indicating the resampling to start and end in specified values (s_startend from my example), even if there are no records in the earliest and latest weeks in my subsample df_pec.



    I thought about artificially adding two entries to df_pec with the real start and real end, but I think it is not so elegant and I don't want to be adding meaningless keys to my df.



    Thank you very much for your wisdom!










    share|improve this question



























      2












      2








      2








      Dear experienced community,
      I can't find an elegant solution to my problem.
      I have a subsample of my dataset which I want to resample weekly, but starting some weeks before the first entry in my data frame (so a few weeks with 0 counts)



      A sample of the data:



      In:



      print(df_pec.head())


      Out:



          Count Image_Sequence_DateTime
      18 1 2015-11-06 03:22:19
      21 1 2015-11-11 01:48:51
      22 1 2015-11-11 07:30:47
      37 1 2015-11-25 09:42:23
      48 1 2015-12-05 12:12:34


      With the earliest image sequence at:



      In:



      df_pec.Image_Sequence_DateTime.min()


      Out:



      2015-09-30 15:16:38


      I have another function that gives me the starting point of the first week and the last point of the last week ever measured in that experiment, which are:



      In:



      print(s_startend)


      Out:



      Start   2015-09-28
      End 2017-12-25
      dtype: datetime64[ns]


      My problem is that I want to resample df_pec weekly, but starting on the very first second of the very first day of the very first week of the experimental deployment.(using s_startend as reference)



      I try:



      df_pec=df_pec.resample('1W', on='Image_Sequence_DateTime').sum() 
      print(df_pec.head(),'n',df_pec.tail())


      Out:



                               Count
      Image_Sequence_DateTime
      2015-10-04 26.0
      2015-10-11 92.0
      2015-10-18 204.0
      2015-10-25 193.0
      2015-11-01 187.0
      Count
      Image_Sequence_DateTime
      2017-11-19 20.0
      2017-11-26 34.0
      2017-12-03 16.0
      2017-12-10 11.0
      2017-12-17 3.0


      This is pretty weird because it is even skipping the first days of data in df_pec.(starting 2015-09-30 15:16:38)



      And even if it worked, I have no way of indicating the resampling to start and end in specified values (s_startend from my example), even if there are no records in the earliest and latest weeks in my subsample df_pec.



      I thought about artificially adding two entries to df_pec with the real start and real end, but I think it is not so elegant and I don't want to be adding meaningless keys to my df.



      Thank you very much for your wisdom!










      share|improve this question
















      Dear experienced community,
      I can't find an elegant solution to my problem.
      I have a subsample of my dataset which I want to resample weekly, but starting some weeks before the first entry in my data frame (so a few weeks with 0 counts)



      A sample of the data:



      In:



      print(df_pec.head())


      Out:



          Count Image_Sequence_DateTime
      18 1 2015-11-06 03:22:19
      21 1 2015-11-11 01:48:51
      22 1 2015-11-11 07:30:47
      37 1 2015-11-25 09:42:23
      48 1 2015-12-05 12:12:34


      With the earliest image sequence at:



      In:



      df_pec.Image_Sequence_DateTime.min()


      Out:



      2015-09-30 15:16:38


      I have another function that gives me the starting point of the first week and the last point of the last week ever measured in that experiment, which are:



      In:



      print(s_startend)


      Out:



      Start   2015-09-28
      End 2017-12-25
      dtype: datetime64[ns]


      My problem is that I want to resample df_pec weekly, but starting on the very first second of the very first day of the very first week of the experimental deployment.(using s_startend as reference)



      I try:



      df_pec=df_pec.resample('1W', on='Image_Sequence_DateTime').sum() 
      print(df_pec.head(),'n',df_pec.tail())


      Out:



                               Count
      Image_Sequence_DateTime
      2015-10-04 26.0
      2015-10-11 92.0
      2015-10-18 204.0
      2015-10-25 193.0
      2015-11-01 187.0
      Count
      Image_Sequence_DateTime
      2017-11-19 20.0
      2017-11-26 34.0
      2017-12-03 16.0
      2017-12-10 11.0
      2017-12-17 3.0


      This is pretty weird because it is even skipping the first days of data in df_pec.(starting 2015-09-30 15:16:38)



      And even if it worked, I have no way of indicating the resampling to start and end in specified values (s_startend from my example), even if there are no records in the earliest and latest weeks in my subsample df_pec.



      I thought about artificially adding two entries to df_pec with the real start and real end, but I think it is not so elegant and I don't want to be adding meaningless keys to my df.



      Thank you very much for your wisdom!







      python python-3.x pandas resampling






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 3 '18 at 10:50







      Ferran F

















      asked Nov 26 '18 at 12:04









      Ferran FFerran F

      304




      304
























          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%2f53480726%2fpandas-resample-starting-before-the-dataset-first-entry%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
















          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%2f53480726%2fpandas-resample-starting-before-the-dataset-first-entry%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

          To store a contact into the json file from server.js file using a class in NodeJS

          Redirect URL with Chrome Remote Debugging Android Devices

          Dieringhausen