当前位置: 首页 > news >正文

有哪些做平面设计好的网站产品网络推广方案

有哪些做平面设计好的网站,产品网络推广方案,珠海网站建设联系方式,wordpress og背景 polars学习系列文章,第7篇 缺失值 该系列文章会分享到github,大家可以去下载jupyter文件,进行参考学习 仓库地址:https://github.com/DataShare-duo/polars_learn 小编运行环境 import sysprint(python 版本:…

背景

polars学习系列文章,第7篇 缺失值

该系列文章会分享到github,大家可以去下载jupyter文件,进行参考学习
仓库地址:https://github.com/DataShare-duo/polars_learn

小编运行环境

import sysprint('python 版本:',sys.version.split('|')[0])
#python 版本: 3.11.9import polars as plprint("polars 版本:",pl.__version__)
#polars 版本: 0.20.22

polars 中缺失值的定义

在 polars 中缺失值用 null 来表示,只有这1种表示方式,这个与 pandas 不同,在 pandas 中 NaN(NotaNumber)也代表是缺失值,但在polars中把 NaN 归属为一种浮点数据

df = pl.DataFrame({"value": [1,2,3, None,5,6,None,8,9],},
)
print(df)
#shape: (9, 1)
┌───────┐
│ value │
│ ---   │
│ i64   │
╞═══════╡
│ 1     │
│ 2     │
│ 3     │
│ null  │
│ 5     │
│ 6     │
│ null  │
│ 8     │
│ 9     │
└───────┘

polars中缺失值包括的2种元信息

  • 缺失值数量,可以通过 null_count 方法来快速获取,因为已经是计算好的,所以调用该方法会立即返回结果
  • 有效位图(validity bitmap),代表是否是缺失值,在内存中用 0 或 1 进行编码来表示,所占的内存空间非常小,通常占用空间为(数据框长度 / 8) bytes,通过 is_null 方法来查看数据是否是缺失值
null_count_df = df.null_count()
print(null_count_df)
#shape: (1, 1)
┌───────┐
│ value │
│ ---   │
│ u32   │
╞═══════╡
│ 2     │
└───────┘is_null_series = df.select(pl.col("value").is_null(),
)
print(is_null_series)
#shape: (9, 1)
┌───────┐
│ value │
│ ---   │
│ bool  │
╞═══════╡
│ false │
│ false │
│ false │
│ true  │
│ false │
│ false │
│ true  │
│ false │
│ false │
└───────┘

缺失值填充

缺失值填充主要通过 fill_null方法来处理,但是需求指定填充缺失值的方法

  • 常量,比如用 0 来填充
  • 填充策略,例如:向前、向后 等
  • 通过表达式,比如利用其他列来填充
  • 插值法
df = pl.DataFrame({"col1": [1, 2, 3],"col2": [1, None, 3],},
)
print(df)
#shape: (3, 2)
┌──────┬──────┐
│ col1 ┆ col2 │
│ ------  │
│ i64  ┆ i64  │
╞══════╪══════╡
│ 11    │
│ 2    ┆ null │
│ 33    │
└──────┴──────┘

常量填充

fill_literal_df = df.with_columns(fill=pl.col("col2").fill_null(pl.lit(2)),
)
print(fill_literal_df)
#shape: (3, 3)
┌──────┬──────┬──────┐
│ col1 ┆ col2 ┆ fill │
│ ---------  │
│ i64  ┆ i64  ┆ i64  │
╞══════╪══════╪══════╡
│ 111    │
│ 2    ┆ null ┆ 2    │
│ 333    │
└──────┴──────┴──────┘

填充策略

填充策略:{‘forward’, ‘backward’, ‘min’, ‘max’, ‘mean’, ‘zero’, ‘one’}

fill_df = df.with_columns(forward=pl.col("col2").fill_null(strategy="forward"),backward=pl.col("col2").fill_null(strategy="backward"),
)
print(fill_df)
#shape: (3, 4)
┌──────┬──────┬─────────┬──────────┐
│ col1 ┆ col2 ┆ forward ┆ backward │
│ ------------      │
│ i64  ┆ i64  ┆ i64     ┆ i64      │
╞══════╪══════╪═════════╪══════════╡
│ 1111        │
│ 2    ┆ null ┆ 13        │
│ 3333        │
└──────┴──────┴─────────┴──────────┘

通过表达式

fill_median_df = df.with_columns(fill=pl.col("col2").fill_null(pl.median("col2")), #类型会转换为浮点型
)
print(fill_median_df)
#shape: (3, 3)
┌──────┬──────┬──────┐
│ col1 ┆ col2 ┆ fill │
│ ---------  │
│ i64  ┆ i64  ┆ f64  │
╞══════╪══════╪══════╡
│ 111.0  │
│ 2    ┆ null ┆ 2.0  │
│ 333.0  │
└──────┴──────┴──────┘

通过插值法

fill_interpolation_df = df.with_columns(fill=pl.col("col2").interpolate(),  
)
print(fill_interpolation_df)
#shape: (3, 3)
┌──────┬──────┬──────┐
│ col1 ┆ col2 ┆ fill │
│ ---------  │
│ i64  ┆ i64  ┆ f64  │
╞══════╪══════╪══════╡
│ 111.0  │
│ 2    ┆ null ┆ 2.0  │
│ 333.0  │
└──────┴──────┴──────┘

历史相关文章

  • Python polars学习-01 读取与写入文件
  • Python polars学习-02 上下文与表达式
  • polars学习-03 数据类型转换
  • Python polars学习-04 字符串数据处理
  • Python polars学习-05 包含的数据结构
  • Python polars学习-06 Lazy / Eager API

以上是自己实践中遇到的一些问题,分享出来供大家参考学习,欢迎关注微信公众号:DataShare ,不定期分享干货

http://www.yidumall.com/news/35884.html

相关文章:

  • 化妆品网站的建设 论文seo搜索引擎优化薪资
  • 网站制作实训企业推广公司
  • 如果启动浏览器就能直接打开一个常用的网站主页_要怎么做?清远新闻最新消息
  • md5 wordpress朝阳seo推广
  • 徐州网站建设外包竞价托管推广多少钱
  • 目前做哪个网站致富郑州发布最新通告
  • 可以做填字游戏的网站新冠咳嗽怎么办
  • 临沂门户网站制作使用网站模板快速建站
  • 做触屏网站天津seo外包
  • qq网站登录入口seo百度关键词排名
  • b2b网站建设内容论文百度一下你就知道了官网
  • wordpress怎么修改css样式一点优化
  • 在阿里国际站做的网站百度seo如何优化关键词
  • 网站建设的过程包括几个阶段合肥网络推广平台
  • 湖南做网站公司有哪些广州抖音推广公司
  • WordPress访问数据插件西安百度seo排名
  • 怎么给网站做外链如何模板建站
  • 水滴保险官方网站百度付费推广
  • 第五冶金建设公司职工大学网站最近一周新闻热点大事件
  • 专业做网站的顺德公司外贸网站推广
  • 深圳网站建设合同建立一个国外的网站
  • 做自动发货网站重庆网
  • 做头像网站有哪些友情链接站长平台
  • 顺德新网站建设照片查询百度图片搜索
  • jsp网站建设项目实战 pdf谷歌浏览器在线入口
  • php开源网站河南做网站优化
  • 昆明网站开发怎样注册网站建立网页
  • 微信订单网站模版seo博客网站
  • 无锡手机网站建设成品短视频app源码的优点
  • 深圳做微信网站建设汕头seo建站