You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pandas的.isna()方法对应的Polars等价方法是什么?

Polars中等价于Pandas .isna()的实现

Pandas 中用于判断空值的isna()方法,在 Polars 中的等价实现是is_null()方法。Polars 底层对空值的统一表述为 null,没有 Pandas 中 NaN、NaT 等不同空值类型的区分,所以统一使用is_null()做空值判断。

常见使用示例

  • 检查整个 DataFrame 的所有值是否为空:
    对应 Pandas 写法 df.isna(),Polars 写法为 df.is_null(),返回布尔类型的 DataFrame,每个位置的布尔值代表原位置是否为空。
  • 检查单个 Series 的值是否为空:
    对应 Pandas 写法 df['列名'].isna(),Polars 写法为 df['列名'].is_null(),返回布尔类型的 Series。
  • 筛选某列不为空的行:
    对应 Pandas 写法 df[~df['列名'].isna()],Polars 写法可以是 df.filter(~pl.col('列名').is_null()),也可以直接用配套的非空判断方法简化为 df.filter(pl.col('列名').is_not_null())。

内容的提问来源于stack exchange,提问作者bolino

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 11:06:03