Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:46:42+00:00 2026-06-14T14:46:42+00:00

I am trying to use resample method to fill the gaps in timeseries data.

  • 0

I am trying to use resample method to fill the gaps in timeseries data. But I also want to know which row was used to fill the missed data.

This is my input series.

In [28]: data
Out[28]: 
Date
2002-09-09    233.25
2002-09-11    233.05
2002-09-16    230.25
2002-09-18    230.10
2002-09-19    230.05
Name: Price

With resample, I will get this

In [29]: data.resample("D", fill_method='bfill')
Out[29]: 
Date
2002-09-09    233.25
2002-09-10    233.05
2002-09-11    233.05
2002-09-12    230.25
2002-09-13    230.25
2002-09-14    230.25
2002-09-15    230.25
2002-09-16    230.25
2002-09-17    230.10
2002-09-18    230.10
2002-09-19    230.05
Freq: D

I am looking for

Out[29]: 
Date
2002-09-09    233.25  2002-09-09
2002-09-10    233.05  2012-09-11
2002-09-11    233.05  2012-09-11
2002-09-12    230.25  2012-09-16
2002-09-13    230.25  2012-09-16
2002-09-14    230.25  2012-09-16
2002-09-15    230.25  2012-09-16
2002-09-16    230.25  2012-09-16
2002-09-17    230.10  2012-09-18  
2002-09-18    230.10  2012-09-18
2002-09-19    230.05  2012-09-19

Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:46:44+00:00Added an answer on June 14, 2026 at 2:46 pm

    After converting the Series to a DataFrame, copy the index into it’s own column. (DatetimeIndex.format() is useful here as it returns a string representation of the index, rather than Timestamp/datetime objects.)

    In [510]: df = pd.DataFrame(data)
    
    In [511]: df['OrigDate'] = df.index.format()
    
    In [513]: df
    Out[513]: 
                 Price    OrigDate
    Date                          
    2002-09-09  233.25  2002-09-09
    2002-09-11  233.05  2002-09-11
    2002-09-16  230.25  2002-09-16
    2002-09-18  230.10  2002-09-18
    2002-09-19  230.05  2002-09-19
    

    For resampling without aggregation, there is a helper method asfreq().

    In [528]: df.asfreq("D", method='bfill')
    Out[528]: 
                 Price    OrigDate
    2002-09-09  233.25  2002-09-09
    2002-09-10  233.05  2002-09-11
    2002-09-11  233.05  2002-09-11
    2002-09-12  230.25  2002-09-16
    2002-09-13  230.25  2002-09-16
    2002-09-14  230.25  2002-09-16
    2002-09-15  230.25  2002-09-16
    2002-09-16  230.25  2002-09-16
    2002-09-17  230.10  2002-09-18
    2002-09-18  230.10  2002-09-18
    2002-09-19  230.05  2002-09-19
    

    This is effectively short-hand for the following, where last() is invoked on the intermediate DataFrameGroupBy objects.

    In [529]: df.resample("D", how='last', fill_method='bfill')
    Out[529]: 
                 Price    OrigDate
    Date                          
    2002-09-09  233.25  2002-09-09
    2002-09-10  233.05  2002-09-11
    2002-09-11  233.05  2002-09-11
    2002-09-12  230.25  2002-09-16
    2002-09-13  230.25  2002-09-16
    2002-09-14  230.25  2002-09-16
    2002-09-15  230.25  2002-09-16
    2002-09-16  230.25  2002-09-16
    2002-09-17  230.10  2002-09-18
    2002-09-18  230.10  2002-09-18
    2002-09-19  230.05  2002-09-19
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying use the Sum method in a lambda expression for a comparison, but
I'm trying use double type in openCL, but doesn't work anyway, i want use
I am trying use filehelpers class builder but I am kinda confused on what
Anyone know how to create a cvCreateStructuringElementEx using a image? I'm trying use opencv.cv.cvCreateStructuringElementEx()
I am trying use Date Picker and on Select i want to display the
Trying to use Net::SFTP, version 2.05 (appears to be the latest). But it fails
Trying to use the http://www.dinnermint.org/css/creating-triangles-in-css/ method to create an arrow _________________ \ \ \
I'm trying to use the R caret module for model generation and I want
I was trying use svn to find a checkin using svn log, but it
I am trying use std::copy to copy from two different iterator. But during course

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.