Resampling or backfilling for a Pandas MultiIndex (to higher freq)

I would like to modify a dataframe of hourly stock prices that has a datetime column with hourly frequencies and missing values. Below is a min example:

date_times =['2020-12-30 14:30:00+00:00',   '2022-03-20 20:00:00+00:00' ]
prices =[25.60, 21.40   ]
stock_names =['AAPL',   'MSFT'  ]
df = pd.DataFrame({'date_time':date_times, 'stock_name':prices, 'price':stock_names})
df.date_time = pd.to_datetime(df.date_time, utc = True )

I would like to bfill or resample this in such a way that it becomes and hourly data for each stock and for the missing values uses the next available one.

Whatever the easiest way is. Maybe recreate a new dataframe with this index and merge? Not sure what the easiest solution is.



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Object oriented programming concepts (OOPs)

Spring Boot and Vaadin : Filtering rows in Vaadin Grid