知道我可以做什么来使用极坐标来模仿下面的 pandas 代码吗?Polars 没有像 pandas 这样的索引,所以我不知道我能做什么。
df = pd.DataFrame(data = ([21,123], [132,412], [23, 43]), columns = ['c1', 'c2']).set_index("c1")
print(df.loc[[23, 132]])
Run Code Online (Sandbox Code Playgroud)
它打印
| c1 | c2 |
|---|---|
| 23 | 43 |
| 132 | 第412章 |
我唯一能想到的极坐标转换是
df = pl.DataFrame(data = ([21,123], [132,412], [23, 43]), schema = ['c1', 'c2'])
print(df.filter(pl.col("c1").is_in([23, 132])))
Run Code Online (Sandbox Code Playgroud)
但它打印
| c1 | c2 |
|---|---|
| 132 | 第412章 |
| 23 | 43 |
这没关系,但行不符合我给出的顺序。我给出了 [23, 132] 并希望输出行的顺序相同,就像 pandas 的输出一样。
是的,我可以稍后使用 sort() ,但是我使用它的原始数据有大约 3000 万行,所以我正在寻找尽可能快的东西。