I have a Polars DataFrame that looks like this:
┌────────────┬───────┐
│ date ┆ value │
│ --- ┆ --- │
│ str ┆ i64 │
╞════════════╪═══════╡
│ 2022-01-01 ┆ 3 │
├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ 2022-01-02 ┆ 7 │
├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ 2022-01-03 ┆ 12 │
└────────────┴───────┘
I have another DataFrame that looks like this:
┌──────────┬───────┬───────┐
│ category ┆ lower ┆ upper │
│ --- ┆ --- ┆ --- │
│ str ┆ i64 ┆ i64 │
╞══════════╪═══════╪═══════╡
│ A ┆ 0 ┆ 5 │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ B ┆ 5 ┆ 10 │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ C ┆ 10 ┆ 15 │
└──────────┴───────┴───────┘
I want to join these two DataFrames so that the first DataFrame has a new column "category" where each row is categorized based on which category it falls between in the second DataFrame. The final DF should look something like this:
┌────────────┬───────┬──────────┐
│ date ┆ value ┆ category │
│ --- ┆ --- ┆ --- │
│ str ┆ i64 ┆ str │
╞════════════╪═══════╪══════════╡
│ 2022-01-01 ┆ 3 ┆ A │
├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ 2022-01-02 ┆ 7 ┆ B │
├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ 2022-01-03 ┆ 12 ┆ C │
└────────────┴───────┴──────────┘
Is there a way to do this efficiently using Polars? What about with an unlimited upper bound on category C?