Skip to content

选中行或列

对行或列进行选择的操作与其他数据框架库类似。

选中列

python
# 推荐写法
df.select(["a", "b"])
# 也可以写成这样
df(["a", "b"])
txt
shape: (5, 2)
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ i64  ┆ str  │
╞══════╪══════╡
│ 1    ┆ foo  │
│ 2    ┆ ham  │
│ 3    ┆ spam │
│ null ┆ egg  │
│ 5    ┆ null │
└──────┴──────┘

选中行

python
df[0:2]
txt

shape: (2, 4)
┌─────┬─────┬──────────┬─────┐
│ a   ┆ b   ┆ c        ┆ d   │
│ --- ┆ --- ┆ ---      ┆ --- │
│ i64 ┆ str ┆ f64      ┆ str │
╞═════╪═════╪══════════╪═════╡
│ 1   ┆ foo ┆ 0.37454  ┆ a   │
│ 2   ┆ ham ┆ 0.950714 ┆ b   │
└─────┴─────┴──────────┴─────┘

基于 MIT 许可发布 共建 共享 共管