Home > Mobile >  How to duplicate values in a Pandas dataframe with a new time resolution
How to duplicate values in a Pandas dataframe with a new time resolution

Time:08-11

I have the following Pandas dataframe: enter image description here

I have a timestamp and a value. I would now like to duplicate the values of the column "value" 4 times and have 15 minute timestamps. So for the timestamps

01.01.2022 00:00 --> 4.8000

01.01.2022 00:15 --> 4.8000

01.01.2022 00:30 --> 4.8000

01.01.2022 00:45 --> 4.8000

And so on

I tried the following but it did not really work:

df['timestamp'] = pd.to_datetime(df['timestamp'], format='%d.%m.%Y %H:%M')
df1 = df.set_index('timestamp').asfreq('15T')
df1['value'].interpolate()

Any idea how I can do that?

CodePudding user response:

Add parameter method='ffill' to Code

Result

It worked for me,

I hope it works for you too,

Best of luck

  • Related