Cloude
Cloude

Reputation: 333

Resampling 15 minute data to 1 minute without aggregation

I have attached the example of a dataframe which is based quarterly. I wish to resample it to per minute without any aggregation

Input dataframe:

Date (CET) Price
2020-01-01 11:00 50
2020-01-01 11:15 60
2020-01-01 11:15 100

The output I want is this:

Date (CET) Price
2020-01-01 11:00 50
2020-01-01 11:01 50
2020-01-01 11:02 50
2020-01-01 11:03 50
2020-01-01 11:04 50
2020-01-01 11:05 50
2020-01-01 11:06 50
2020-01-01 11:07 50
2020-01-01 11:08 50
2020-01-01 11:09 50
2020-01-01 11:10 50
2020-01-01 11:11 50
2020-01-01 11:12 50
2020-01-01 11:13 50
2020-01-01 11:14 50
2020-01-01 11:15 60

I tried using df.resample, but it requires me to aggregated based on the mean() or sum(), which I don't want. I want the values to remain the same for a particular quarter. Like in the output table the price remains 50 from 11:00 to 11:14

Upvotes: 2

Views: 1220

Answers (1)

jezrael
jezrael

Reputation: 862781

Use:

#convert to DatetimeIndex
df['Date (CET)'] = pd.to_datetime(df['Date (CET)'])

#remove duplicates
df = df.drop_duplicates('Date (CET)')

df = df.set_index('Date (CET)')

#forward filling values - upsample
df.resample('Min').ffill()

Upvotes: 1

Related Questions