Skip to content Skip to sidebar Skip to footer

When Upscaling Pandas Dataframe, Don't Fill Beyond Time Period Of Each Row

I run into undesired behaviour when upscaling a dataframe using Python's pandas library. Example Let's start with monthly data: carMonthly = pd.DataFrame(data={'avSpeed': [40.3, 23

Solution 1:

You should resample with in the groupby

s=carMonthly.groupby(level=0).apply(lambda x : x.resample('D').ffill())
s['dist']/=s.groupby(level=0)['avSpeed'].transform('count').values
s.reset_index(level=0,drop=True,inplace=True)

Post a Comment for "When Upscaling Pandas Dataframe, Don't Fill Beyond Time Period Of Each Row"