79279698

Date: 2024-12-13 22:19:49
Score: 1
Natty:
Report link

If df is the given dataframe with 7 rows,

df.set_index('date', inplace=True)  # date as index

Create the main dataframe df2 with one row per minute

timestamps = pd.date_range('2024-12-12 10:43', '2024-12-14 05:42', freq='1min') 
df2 = pd.DataFrame({'value': np.nan}, index=timestamps)

df2.loc[df.index] = df  # fill with the known values in df
df2['value'].fillna(method='ffill', inplace=True)  # forward fill the missing values (bfill for backfoward)

display(df2[-25:-15])

res

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: rehaqds