I'm trying to upsample a Polars dataframe while grouping by a particular column. In the following example, I wish to group by 'fruit' and then upsample by date.
fruit | date | count |
---|---|---|
apple | 2022-06-01 | 5 |
apple | 2022-06-03 | 6 |
apple | 2022-06-04 | 2 |
apple | 2022-06-07 | 1 |
pear | 2022-06-01 | 9 |
pear | 2022-06-07 | 12 |
This is what the output should look like:
fruit | date | count |
---|---|---|
apple | 2022-06-01 | 5 |
apple | 2022-06-02 | 5 |
apple | 2022-06-03 | 6 |
apple | 2022-06-04 | 2 |
apple | 2022-06-05 | 2 |
apple | 2022-06-06 | 2 |
apple | 2022-06-07 | 1 |
pear | 2022-06-01 | 9 |
pear | 2022-06-02 | 9 |
pear | 2022-06-03 | 9 |
pear | 2022-06-04 | 9 |
pear | 2022-06-05 | 9 |
pear | 2022-06-06 | 9 |
pear | 2022-06-07 | 12 |
For a non group-by scenario, the following command gets me the result I need:
df.upsample('date', every='1d').fill_null("forward")
However, I've not been able to get it working when a groupby is involved
ps: here is a similar question, but using pandas - Pandas: resample timeseries with groupby