我想通过根据数量列中的值重复行来扩展以下Polars数据框。
原始数据框:
| 水果 | 数量 |
|---|---|
| 苹果 | 2 |
| 香蕉 | 3 |
预期输出:
| 水果 | 数量 |
|---|---|
| 苹果 | 1 |
| 苹果 | 1 |
| 香蕉 | 1 |
| 香蕉 | 1 |
| 香蕉 | 1 |
这是一个非常相似的问题,但使用 Pandas 而不是 Polars:Repeat rows in a pandas DataFrame based on column value
Polars 重复函数似乎没有提供与 Pandas 对应函数相同的功能:https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.repeat.html