Python酷库之旅-第三方库Pandas(037)

news2024/9/21 0:47:22

目录

一、用法精讲

116、pandas.Series.div方法

116-1、语法

116-2、参数

116-3、功能

116-4、返回值

116-5、说明

116-6、用法

116-6-1、数据准备

116-6-2、代码示例

116-6-3、结果输出

117、pandas.Series.truediv方法

117-1、语法

117-2、参数

117-3、功能

117-4、返回值

117-5、说明

117-6、用法

117-6-1、数据准备

117-6-2、代码示例

117-6-3、结果输出

118、pandas.Series.floordiv方法

118-1、语法

118-2、参数

118-3、功能

118-4、返回值

118-5、说明

118-6、用法

118-6-1、数据准备

118-6-2、代码示例

118-6-3、结果输出

119、pandas.Series.mod方法

119-1、语法

119-2、参数

119-3、功能

119-4、返回值

119-5、说明

119-6、用法

119-6-1、数据准备

119-6-2、代码示例

119-6-3、结果输出

120、pandas.Series.pow方法

120-1、语法

120-2、参数

120-3、功能

120-4、返回值

120-5、说明

120-6、用法

120-6-1、数据准备

120-6-2、代码示例

120-6-3、结果输出

二、推荐阅读

1、Python筑基之旅

2、Python函数之旅

3、Python算法之旅

4、Python魔法之旅

5、博客个人主页

一、用法精讲

116、pandas.Series.div方法
116-1、语法
# 116、pandas.Series.div方法
pandas.Series.div(other, level=None, fill_value=None, axis=0)
Return Floating division of series and other, element-wise (binary operator truediv).

Equivalent to series / other, but with support to substitute a fill_value for missing data in either one of the inputs.

Parameters:
other
Series or scalar value
level
int or name
Broadcast across a level, matching Index values on the passed MultiIndex level.

fill_value
None or float value, default None (NaN)
Fill existing missing (NaN) values, and any new element needed for successful Series alignment, with this value before computation. If data in both corresponding Series locations is missing the result of filling (at that location) will be missing.

axis
{0 or ‘index’}
Unused. Parameter needed for compatibility with DataFrame.

Returns:
Series
The result of the operation.
116-2、参数

116-2-1、other(必须)标量、Series或DataFrame,表示要除以的值,可以是一个标量、另一个Series或DataFrame,如果是Series或DataFrame,则会根据索引进行对齐。

116-2-2、level(可选,默认值为None)一个整数或字符串,如果other是一个MultiIndex的Series或DataFrame,使用该参数可以指定索引的哪个层进行对齐,传入的值应该是层的级别的名称或位置(索引值)。

116-2-3、fill_value(可选,默认值为None)标量值,当对齐时,如果某个Series中的某个索引值在另一个Series中不存在,可以通过此参数提供一个填充值,以在计算时替换缺失值,默认为None,即缺失值会返回NaN

116-2-4、axis(可选,默认值为0)当other是DataFrame时,此参数指定沿哪个轴进行操作;对于Series,通常不需要使用此参数,默认值为0。

116-3、功能

        用于执行元素级除法的函数,它可以将当前Series的每个元素除以另一个Series或标量值。

116-4、返回值

        返回一个新的Series,其中包含除法运算的结果。如果参与运算的两个对象没有相同的索引,结果中缺失的索引会被填充为NaN(若未设置fill_value)。

116-5、说明

        无

116-6、用法
116-6-1、数据准备
116-6-2、代码示例
# 116、pandas.Series.div方法
import pandas as pd
# 创建一个Series
s1 = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
s2 = pd.Series([1, 2, 3], index=['a', 'b', 'd'])
# 使用div方法
result = s1.div(s2, fill_value=0)
print(result)
116-6-3、结果输出
# 116、pandas.Series.div方法
# a    10.0
# b    10.0
# c     inf
# d     0.0
# dtype: float64
117、pandas.Series.truediv方法
117-1、语法
# 117、pandas.Series.truediv方法
pandas.Series.truediv(other, level=None, fill_value=None, axis=0)
Return Floating division of series and other, element-wise (binary operator truediv).

Equivalent to series / other, but with support to substitute a fill_value for missing data in either one of the inputs.

Parameters:
other
Series or scalar value
level
int or name
Broadcast across a level, matching Index values on the passed MultiIndex level.

fill_value
None or float value, default None (NaN)
Fill existing missing (NaN) values, and any new element needed for successful Series alignment, with this value before computation. If data in both corresponding Series locations is missing the result of filling (at that location) will be missing.

axis
{0 or ‘index’}
Unused. Parameter needed for compatibility with DataFrame.

Returns:
Series
The result of the operation.
117-2、参数

117-2-1、other(必须)标量、Series或DataFrame,表示要进行除法运算的值,可以是标量、另一个Series或DataFrame,如果other是Series或DataFrame,则会根据索引进行对齐。

117-2-2、level(可选,默认值为None)一个整数或字符串,如果other是具有MultiIndex的Series或DataFrame,使用该参数可以指定索引的哪个层进行对齐,level可以是层的名称或位置(索引值)。

117-2-3、fill_value(可选,默认值为None)标量值,在对齐过程中,如果某个Series的某个索引值在另一个Series或DataFrame中不存在,可以通过此参数提供一个填充值,以在计算时替换缺失值,默认值为None,即缺失值会返回NaN。

117-2-4、axis(可选,默认值为0)当other是DataFrame时,此参数指定沿哪个轴进行操作;对于Series,通常不需要使用此参数,默认值为0(即沿索引方向)。

117-3、功能

        用于执行元素级的真除法运算,它与Series.div()方法的主要区别在于truediv明确表示执行浮点除法(即除法结果是浮点数),而div方法默认会根据传入的数据类型自动选择整数除法或浮点除法。

117-4、返回值

        返回一个新的Series,其中包含除法运算的结果,如果参与运算的两个对象没有相同的索引,结果中缺失的索引会被填充为NaN(若未设置fill_value)。

117-5、说明

        无

117-6、用法
117-6-1、数据准备
117-6-2、代码示例
# 117、pandas.Series.truediv方法
import pandas as pd
# 创建两个Series
s1 = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
s2 = pd.Series([1, 2, 3], index=['a', 'b', 'd'])
# 使用truediv方法进行真除法
result = s1.truediv(s2, fill_value=1)  
print(result)
117-6-3、结果输出
# 117、pandas.Series.truediv方法
# a    10.000000
# b    10.000000
# c    30.000000
# d     0.333333
# dtype: float64
118、pandas.Series.floordiv方法
118-1、语法
# 118、pandas.Series.floordiv方法
pandas.Series.floordiv(other, level=None, fill_value=None, axis=0)
Return Integer division of series and other, element-wise (binary operator floordiv).

Equivalent to series // other, but with support to substitute a fill_value for missing data in either one of the inputs.

Parameters:
other
Series or scalar value
level
int or name
Broadcast across a level, matching Index values on the passed MultiIndex level.

fill_value
None or float value, default None (NaN)
Fill existing missing (NaN) values, and any new element needed for successful Series alignment, with this value before computation. If data in both corresponding Series locations is missing the result of filling (at that location) will be missing.

axis
{0 or ‘index’}
Unused. Parameter needed for compatibility with DataFrame.

Returns:
Series
The result of the operation.
118-2、参数

118-2-1、other(必须)标量、Series或DataFrame,表示要进行地板除法运算的值,可以是标量、另一个 Series或DataFrame,如果other是Series或DataFrame,则会根据索引进行对齐。

118-2-2、level(可选,默认值为None)一个整数或字符串,如果other是具有MultiIndex的Series或DataFrame,使用该参数可以指定索引的哪个层进行对齐,level可以是层的名称或位置(索引值)。

118-2-3、fill_value(可选,默认值为None)标量值,在对齐过程中,如果某个Series的某个索引值在另一个Series或DataFrame中不存在,可以通过此参数提供一个填充值,以在计算时替换缺失值,默认值为None,即缺失值会返回NaN

118-2-4、axis(可选,默认值为0)一个整数或字符串,当other是DataFrame时,此参数指定沿哪个轴进行操作;对于Series,通常不需要使用此参数,默认值为0(即沿索引方向)。

118-3、功能

        用于执行元素级的地板除法运算,该运算的结果是向下取整的整数除法,即不管余数是多少,结果都会向下舍入到最接近的整数。

118-4、返回值

        返回一个新的Series,其中包含地板除法运算的结果,对于不存在的索引值,结果中将填充为NaN(若未设置fill_value)。

118-5、说明

        无

118-6、用法
118-6-1、数据准备
118-6-2、代码示例
# 118、pandas.Series.floordiv方法
import pandas as pd
# 创建两个Series
s1 = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
s2 = pd.Series([3, 4, 7], index=['a', 'b', 'd'])
# 使用floordiv方法进行地板除法
result = s1.floordiv(s2, fill_value=1)
print(result)
118-6-3、结果输出
# 118、pandas.Series.floordiv方法
# a     3.0
# b     5.0
# c    30.0
# d     0.0
# dtype: float64
119、pandas.Series.mod方法
119-1、语法
# 119、pandas.Series.mod方法
pandas.Series.mod(other, level=None, fill_value=None, axis=0)
Return Modulo of series and other, element-wise (binary operator mod).

Equivalent to series % other, but with support to substitute a fill_value for missing data in either one of the inputs.

Parameters:
other
Series or scalar value
level
int or name
Broadcast across a level, matching Index values on the passed MultiIndex level.

fill_value
None or float value, default None (NaN)
Fill existing missing (NaN) values, and any new element needed for successful Series alignment, with this value before computation. If data in both corresponding Series locations is missing the result of filling (at that location) will be missing.

axis
{0 or ‘index’}
Unused. Parameter needed for compatibility with DataFrame.

Returns:
Series
The result of the operation.
119-2、参数

119-2-1、other(必须)标量、Series或DataFrame,表示要进行模运算的值,可以是标量、另一个Series或DataFrame,如果other是Series或DataFrame,则会根据索引进行对齐。

119-2-2、level(可选,默认值为None)一个整数或字符串,如果other是具有MultiIndex的Series或DataFrame,使用该参数可以指定索引的哪个层进行对齐,level可以是层的名称或位置(索引值)。

119-2-3、fill_value(可选,默认值为None)标量值,在对齐过程中,如果某个Series的某个索引值在另一个Series或DataFrame中不存在,可以通过此参数提供一个填充值,以在计算时替换缺失值,默认值为None,即缺失值会返回NaN。

119-2-4、axis(可选,默认值为0)当other是DataFrame时,此参数指定沿哪个轴进行操作;对于Series,通常不需要使用此参数,默认值为0(即沿索引方向)。

119-3、功能

        用于执行元素级的模运算(取余运算),该运算将每个元素除以给定的值,并返回余数。

119-4、返回值

        返回一个新的Series,其中包含模运算的结果,对于不存在的索引值,结果中将填充为NaN(若未设置fill_value)。

119-5、说明

119-5-1、对齐:当other是另一个Series或DataFrame时,mod()会根据索引进行对齐,如果索引不匹配,可能会得到NaN(除非使用fill_value填充)。

119-5-2、数据类型:模运算的结果将具有与输入Series相同的数据类型。对于整数类型的Series,结果也是整数类型;对于浮点型,结果将是浮点型。

119-6、用法
119-6-1、数据准备
119-6-2、代码示例
# 119、pandas.Series.mod方法
import pandas as pd
# 创建两个Series
s1 = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
s2 = pd.Series([3, 4, 7], index=['a', 'b', 'd'])
# 使用mod方法进行模运算
result = s1.mod(s2, fill_value=1)
print(result)
119-6-3、结果输出
# 119、pandas.Series.mod方法
# a    1.0
# b    0.0
# c    0.0
# d    1.0
# dtype: float64
120、pandas.Series.pow方法
120-1、语法
# 120、pandas.Series.pow方法
pandas.Series.pow(other, level=None, fill_value=None, axis=0)
Return Exponential power of series and other, element-wise (binary operator pow).

Equivalent to series ** other, but with support to substitute a fill_value for missing data in either one of the inputs.

Parameters:
other
Series or scalar value
level
int or name
Broadcast across a level, matching Index values on the passed MultiIndex level.

fill_value
None or float value, default None (NaN)
Fill existing missing (NaN) values, and any new element needed for successful Series alignment, with this value before computation. If data in both corresponding Series locations is missing the result of filling (at that location) will be missing.

axis
{0 or ‘index’}
Unused. Parameter needed for compatibility with DataFrame.

Returns:
Series
The result of the operation.
120-2、参数

120-2-1、other(必须)标量、Series或DataFrame,表示幂运算的指数,可以是标量(单一的幂值),也可以是另一个Series或DataFrame,如果other是Series或DataFrame,则会根据索引进行对齐。

120-2-2、level(可选,默认值为None)一个整数或字符串,如果other是具有MultiIndex的Series或DataFrame,使用该参数可以指定索引的哪个层进行对齐,level可以是层的名称或位置(索引值)。

120-2-3、fill_value(可选,默认值为None)标量值,在对齐过程中,如果某个Series的某个索引值在另一个Series或DataFrame中不存在,可以通过此参数提供一个填充值,以在计算时替换缺失值,默认值为None,即缺失值会返回NaN。

120-2-4、axis(可选,默认值为0)当other是DataFrame时,此参数指定沿哪个轴进行操作;对于Series,通常不需要使用此参数,默认值为0(即沿索引方向)。

120-3、功能

        用于对Series中的每个元素进行幂运算,它的功能是将Series的每个元素的值提高到指定的幂次。

120-4、返回值

        返回一个新的Series,其中包含幂运算的结果,对于不存在的索引值,结果中将填充为NaN(若未设置fill_value)。

120-5、说明

120-5-1、对齐:当other是另一个Series或DataFrame时,pow()方法会根据索引进行对齐,如果索引不匹配,可能会得到NaN(除非使用fill_value填充)。

120-5-2、数据类型:幂运算的结果将具有与输入Series相同的数据类型,对于整数类型的Series,结果也是整数类型;对于浮点型,结果将是浮点型。

120-6、用法
120-6-1、数据准备
120-6-2、代码示例
# 120、pandas.Series.pow方法
import pandas as pd
# 创建两个Series
s1 = pd.Series([2, 3, 4], index=['a', 'b', 'c'])
s2 = pd.Series([1, 2, 3], index=['a', 'b', 'd'])
# 使用pow方法进行幂运算
result = s1.pow(s2, fill_value=0)
print(result)
120-6-3、结果输出
# 120、pandas.Series.pow方法
# a    2.0
# b    9.0
# c    1.0
# d    0.0
# dtype: float64

二、推荐阅读

1、Python筑基之旅
2、Python函数之旅
3、Python算法之旅
4、Python魔法之旅
5、博客个人主页

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1940496.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

C语言编译报错:error: expected declaration or statement at end of input(缺了括号)

文章目录 报错信息分析解决步骤: 排查 报错信息 /userdata/testOtherPrj/20240715_box_circuit_breaker/test/external/modbus_vendorA/src/vendor_a_modbus.c: In function ‘VendorA_PowerStop’: /userdata/testOtherPrj/20240715_box_circuit_breaker/test/exte…

25届近4年电子科技大学自动化考研院校分析

电子科技大学 目录 一、学校学院专业简介 二、考试科目指定教材 三、近4年考研分数情况 四、近4年招生录取情况 五、最新一年分数段图表 六、初试大纲复试大纲 七、学费&奖学金&就业方向 一、学校学院专业简介 二、考试科目指定教材 1、考试科目介绍 2、指定教…

EasyAnimate-v3 实测,阿里开源视频生成模型,5 分钟带你部署体验,支持高分辨率超长视频

自从 Sora 发布以来,AI 视频生成的热度不减,社区中涌现了大量类 Sora 的开源项目。 前不久,快手开放了可灵视频生成模型的内测,不过可灵是闭源的,相信很多小伙伴还没拿到内测名额。 今天给大家分享一款开源的视频生成…

Springboot 启动时Bean的创建与注入(一)-面试热点-springboot源码解读-xunznux

Springboot 启动时Bean的创建与注入,以及对应的源码解读 文章目录 Springboot 启动时Bean的创建与注入,以及对应的源码解读构建Web项目流程图:堆栈信息:堆栈信息简介堆栈信息源码详解1、main:10, DemoApplication (com.xun.demo)2…

currentTarget和target

*.wxml *.js 点击按钮 发现 currentTarget 获取的是事件绑定者的参数 target 获取的是事件触发者的参数

vue3前端开发-小兔鲜项目-一级页面产品列表渲染

vue3前端开发-小兔鲜项目-一级页面产品列表渲染! 这一次做两件事。第一个是给导航栏增加一个动态标记的属性。第二件事是渲染一下一级页面内产品列表。 第一件事,很简单,路由器插件,自带了这种属性。 如图所示,有一个…

最新CSM客户成功 OKR 案例:以指导、激励和调整您的团队

客户是任何企业的命脉,而客户服务是与客户接触的第一站,是实现目标和扩大组织规模是以保留客户和追加销售为前提的。 客户成功CSM是一种商业方法,确保客户在使用你的产品/服务时达到他们想要的结果。客户成功是以关系为中心的客户管理&#…

昇思25天学习打卡营第22天|ResNet50图像分类

ResNet网络介绍 ResNet50网络是2015年由微软实验室的何恺明提出,获得ILSVRC2015图像分类竞赛第一名。在ResNet网络提出之前,传统的卷积神经网络都是将一系列的卷积层和池化层堆叠得到的,但当网络堆叠到一定深度时,就会出现退化问…

Linux系统编程基础

Linux操作系统 Linux不是一个具体的操作系统,而是一类操作系统的总称,具体版本成为发行版。 Red Hat:目前被IBM收购,收费版,目前最大的Linux供应商CentOS: Red Hat退出的免费版Ubuntu:界面比较友…

公司技术栈用到了RocketMQ,我对此块知识进行了回顾(初始RocketMQ)

前言 作为24届的校招生,不知道大伙儿们是否都已经到了工作岗位上。为了以后更方便的接触到公司的业务,我司为我们安排了将近一个月的实操。虽然不用敲代码,但是… 了解到我司使用到的技术栈,在空闲时间正好对RocketMQ这块技术做个…

Redis集群部署Windows版本

Redis集群 之前因为数据量的原因,并没有进行Redis集群的配置需要,现在由于数据量大,需要进行集群部署。 最初在windows系统部署,需要Redis的windows版本,但官方没有windows版本,所以需要去gitHub上找由民…

git使用-命令行+VS Code结合使用

一、Git常用命令 // 显示当分支的状态。它会列出已修改、已暂存和未跟踪的文件 git status// 列出本地仓库中所有的分支,其中会特殊显示当前所在分支 git branch// 在当前分支的基础上创建一个新的分支,并切换到这个新的分支上 git checkout -b 新分支…

超声波清洗机洗眼镜好吗?一篇文章告诉你买超声波清洗机有必要吗

眼镜党们,你们是不是也有眼镜清洁的烦恼?日常生活中,我们佩戴的眼镜很容易就会沾上脏污,而经常擦拭又会损伤眼镜镜片,而且,长时间未清洁的尘埃、油脂乃至细菌,会影响我们的视觉健康,…

被问到MQ消息已丢失,该如何处理?

在分布式系统中,消息中间件(如 RabbitMQ、RocketMQ、Kafka、Pulsar 等)扮演着关键角色,用于解耦生产者和消费者,并确保数据传输的可靠性和顺序性。尽管我们通常会采取多种措施来防止消息丢失,如消息持久化、…

【C语言】动态内存管理(上)

文章目录 前言1.为什么要存在动态内存2. malloc和free2.1 malloc2.2 free2.3 使用实例(malloc和free) 3. calloc3.1 calloc例子 前言 本文开始将开始学习C语言中一个比较重要的知识点或者是操作——动态内存管理。由于本次的知识比较重要,为…

git 提交的进阶操作

cherry-pick cherry-pick 是 Git 中的一种操作,允许你从一个分支中选择特定的 commit,并将其应用到另一个分支。它的主要用途是将特定的更改引入到其他分支,而无需合并整个分支历史。这在修复 bug 或者移植某些功能时特别有用。 cherry-pick 的使用场景 Bug 修复: 例如,你…

WhisperX

文章目录 一、关于 WhisperX新闻 🚨 二、设置⚙️1、创建Python3.10环境2、安装PyTorch,例如Linux和Windows CUDA11.8:3、安装此repo4、Speaker Diarization 三、使用💬(命令行)1、English2、他语言例如德语…

厦门会展可视化:展览全方位动态展示

通过图扑先进的可视化技术,实时呈现厦门会展中心的各类活动和展览布局,提供直观的导航和详细的展区信息,让参观者轻松完成数字化体验。

ELK日志管理与应用

目录 一.ELK收集nginx日志 二.收集tomcat日志 三.Filebeat 一.ELK收集nginx日志 1.搭建好ELKlogstashkibana架构 2.关闭防火墙和selinux systemctl stop firewalld setenforce 0 3.安装nginx [rootlocalhost ~]# yum install epel-release.noarch -y [rootlocalhost …

谷粒商城实战笔记-37-前端基础-Vue-基本语法插件安装

文章目录 一,v-model1,双向绑定2,vue的双向绑定2.1 html元素上使用指令v-model2.2 model中声明对应属性2.3,验证view绑定modelmodel绑定view 完整代码 二,v-on1,指令简介2,在button按钮中添加v-…