Increase Sampling rate on time-series data with Pandas












0














I have accelerometer data with variable sampling rate. I am trying to increase it a constant sampling rate 50hz through interpolation.The problem with the timestamps is, it doesn't have milliseconds.
enter image description here



How do i do it without losing the data i already have?










share|improve this question



























    0














    I have accelerometer data with variable sampling rate. I am trying to increase it a constant sampling rate 50hz through interpolation.The problem with the timestamps is, it doesn't have milliseconds.
    enter image description here



    How do i do it without losing the data i already have?










    share|improve this question

























      0












      0








      0







      I have accelerometer data with variable sampling rate. I am trying to increase it a constant sampling rate 50hz through interpolation.The problem with the timestamps is, it doesn't have milliseconds.
      enter image description here



      How do i do it without losing the data i already have?










      share|improve this question













      I have accelerometer data with variable sampling rate. I am trying to increase it a constant sampling rate 50hz through interpolation.The problem with the timestamps is, it doesn't have milliseconds.
      enter image description here



      How do i do it without losing the data i already have?







      python pandas






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 16:01









      subhash

      85111




      85111
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You can first set the index as your datetime column using df.set_index('timestamp') and use df.resample(). The directive you want to pass into the resample function is L for milliseconds, but you can read more here. The resample function also lets you choose a number of interpolation modes.






          share|improve this answer





















          • I tried this df.resample('20ms', on='timestamp'). This only take first occurence's value and increases the sampling rate but all the rest of data for that particular second is lost. Its just populated as nan.
            – subhash
            Nov 19 '18 at 16:10






          • 1




            I see. That's tricky because to pandas, it just sees a bunch of values with the same timestamp and doesn't know what to do with it. Moreover, it doesn't even seem that there are always the same number of repeated timestamps. It seems you may have roll something manually; basically go second by second, assume all values for a given second are spaced out evenly for a second, and interpolate using the mean of neighbors or something.
            – rvd
            Nov 19 '18 at 16:14










          • Another possible way is to go through second by second and change the timestamps so that they are spaced evenly by for how many times a second value repeats, and then use resample to fill everything else. This way pandas will still do most of the work.
            – rvd
            Nov 19 '18 at 16: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',
          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%2f53378457%2fincrease-sampling-rate-on-time-series-data-with-pandas%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









          0














          You can first set the index as your datetime column using df.set_index('timestamp') and use df.resample(). The directive you want to pass into the resample function is L for milliseconds, but you can read more here. The resample function also lets you choose a number of interpolation modes.






          share|improve this answer





















          • I tried this df.resample('20ms', on='timestamp'). This only take first occurence's value and increases the sampling rate but all the rest of data for that particular second is lost. Its just populated as nan.
            – subhash
            Nov 19 '18 at 16:10






          • 1




            I see. That's tricky because to pandas, it just sees a bunch of values with the same timestamp and doesn't know what to do with it. Moreover, it doesn't even seem that there are always the same number of repeated timestamps. It seems you may have roll something manually; basically go second by second, assume all values for a given second are spaced out evenly for a second, and interpolate using the mean of neighbors or something.
            – rvd
            Nov 19 '18 at 16:14










          • Another possible way is to go through second by second and change the timestamps so that they are spaced evenly by for how many times a second value repeats, and then use resample to fill everything else. This way pandas will still do most of the work.
            – rvd
            Nov 19 '18 at 16:15
















          0














          You can first set the index as your datetime column using df.set_index('timestamp') and use df.resample(). The directive you want to pass into the resample function is L for milliseconds, but you can read more here. The resample function also lets you choose a number of interpolation modes.






          share|improve this answer





















          • I tried this df.resample('20ms', on='timestamp'). This only take first occurence's value and increases the sampling rate but all the rest of data for that particular second is lost. Its just populated as nan.
            – subhash
            Nov 19 '18 at 16:10






          • 1




            I see. That's tricky because to pandas, it just sees a bunch of values with the same timestamp and doesn't know what to do with it. Moreover, it doesn't even seem that there are always the same number of repeated timestamps. It seems you may have roll something manually; basically go second by second, assume all values for a given second are spaced out evenly for a second, and interpolate using the mean of neighbors or something.
            – rvd
            Nov 19 '18 at 16:14










          • Another possible way is to go through second by second and change the timestamps so that they are spaced evenly by for how many times a second value repeats, and then use resample to fill everything else. This way pandas will still do most of the work.
            – rvd
            Nov 19 '18 at 16:15














          0












          0








          0






          You can first set the index as your datetime column using df.set_index('timestamp') and use df.resample(). The directive you want to pass into the resample function is L for milliseconds, but you can read more here. The resample function also lets you choose a number of interpolation modes.






          share|improve this answer












          You can first set the index as your datetime column using df.set_index('timestamp') and use df.resample(). The directive you want to pass into the resample function is L for milliseconds, but you can read more here. The resample function also lets you choose a number of interpolation modes.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 16:07









          rvd

          43117




          43117












          • I tried this df.resample('20ms', on='timestamp'). This only take first occurence's value and increases the sampling rate but all the rest of data for that particular second is lost. Its just populated as nan.
            – subhash
            Nov 19 '18 at 16:10






          • 1




            I see. That's tricky because to pandas, it just sees a bunch of values with the same timestamp and doesn't know what to do with it. Moreover, it doesn't even seem that there are always the same number of repeated timestamps. It seems you may have roll something manually; basically go second by second, assume all values for a given second are spaced out evenly for a second, and interpolate using the mean of neighbors or something.
            – rvd
            Nov 19 '18 at 16:14










          • Another possible way is to go through second by second and change the timestamps so that they are spaced evenly by for how many times a second value repeats, and then use resample to fill everything else. This way pandas will still do most of the work.
            – rvd
            Nov 19 '18 at 16:15


















          • I tried this df.resample('20ms', on='timestamp'). This only take first occurence's value and increases the sampling rate but all the rest of data for that particular second is lost. Its just populated as nan.
            – subhash
            Nov 19 '18 at 16:10






          • 1




            I see. That's tricky because to pandas, it just sees a bunch of values with the same timestamp and doesn't know what to do with it. Moreover, it doesn't even seem that there are always the same number of repeated timestamps. It seems you may have roll something manually; basically go second by second, assume all values for a given second are spaced out evenly for a second, and interpolate using the mean of neighbors or something.
            – rvd
            Nov 19 '18 at 16:14










          • Another possible way is to go through second by second and change the timestamps so that they are spaced evenly by for how many times a second value repeats, and then use resample to fill everything else. This way pandas will still do most of the work.
            – rvd
            Nov 19 '18 at 16:15
















          I tried this df.resample('20ms', on='timestamp'). This only take first occurence's value and increases the sampling rate but all the rest of data for that particular second is lost. Its just populated as nan.
          – subhash
          Nov 19 '18 at 16:10




          I tried this df.resample('20ms', on='timestamp'). This only take first occurence's value and increases the sampling rate but all the rest of data for that particular second is lost. Its just populated as nan.
          – subhash
          Nov 19 '18 at 16:10




          1




          1




          I see. That's tricky because to pandas, it just sees a bunch of values with the same timestamp and doesn't know what to do with it. Moreover, it doesn't even seem that there are always the same number of repeated timestamps. It seems you may have roll something manually; basically go second by second, assume all values for a given second are spaced out evenly for a second, and interpolate using the mean of neighbors or something.
          – rvd
          Nov 19 '18 at 16:14




          I see. That's tricky because to pandas, it just sees a bunch of values with the same timestamp and doesn't know what to do with it. Moreover, it doesn't even seem that there are always the same number of repeated timestamps. It seems you may have roll something manually; basically go second by second, assume all values for a given second are spaced out evenly for a second, and interpolate using the mean of neighbors or something.
          – rvd
          Nov 19 '18 at 16:14












          Another possible way is to go through second by second and change the timestamps so that they are spaced evenly by for how many times a second value repeats, and then use resample to fill everything else. This way pandas will still do most of the work.
          – rvd
          Nov 19 '18 at 16:15




          Another possible way is to go through second by second and change the timestamps so that they are spaced evenly by for how many times a second value repeats, and then use resample to fill everything else. This way pandas will still do most of the work.
          – rvd
          Nov 19 '18 at 16: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%2f53378457%2fincrease-sampling-rate-on-time-series-data-with-pandas%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

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith