Reputation: 725
I have a dataframe in hourly granularity and I would like to return the dataframe with only a part of it resampled.
That part will be a specific date, for example resample_start_date
So far I have the following code
import pandas as pd
import numpy as np
import datetime
resample_start_date = datetime.datetime(2016,7,1)
Date = pd.date_range("2016-05-01", "2016-10-01", freq="H", name='Date')
Puissance = {'Puissance': np.random.rand(len(Date))}
df = pd.DataFrame(Puissance, index=Date)
df2 = df.resample('MS').mean().reindex(index=df.index, method='ffill')
But this code resamples the whole dataframe. My objective is to keep the first period till resample_start_date
the same and after that to resample monthly.
Upvotes: 0
Views: 101
Reputation: 150735
Something in this line:
pd.concat((df.loc[:resample_start_date],
df.loc[resample_start_date:].resample('M').mean()
))
Upvotes: 2