Python酷库之旅-第三方库Pandas(037)
目录
一、用法精讲
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、博客个人主页
相关文章:

Python酷库之旅-第三方库Pandas(037)
目录 一、用法精讲 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、功能 …...
iOS 左滑返回事件的控制
0x00 视图结构 1-根视图 1.1-控制器A 1.1.1-控制器B 1.1.1.1-控制器C 0x01 控制 通过设置 self.navigationController.interactivePopGestureRecognizer.enabled 为 YES 或 NO 来控制当面界面,是否能左滑返回 在 控制器B 的生命周期方法内,设置属性 s…...

= null 和 is null;SQL中关于NULL处理的4个陷阱;三值逻辑
一、概述 1、NULL参与的所有的比较和算术运算符(>,,<,<>,<,>,,-,*,/) 结果为unknown; 2、unknown的逻辑运算(AND、OR、NOT)遵循三值运算的真值表; 3、如果运算结果直接返回用户,使用NULL来标识unknown 4、如…...

拖拽上传(预览图片)
需求 点击上传图片,或直接拖拽图片到红色方框里面也可上传图片,上传后预览图片 效果 实现 <!DOCTYPE html> <html lang"zh-cn"><head><meta charset"UTF-8"><meta name"viewport" content&…...
Oracle 12c新特性 In-Memory Column Store
Oracle 12c引入了一项重要的特性——In-Memory Column Store(简称IM或In-Memory),这一特性极大地提升了数据库在处理分析型查询时的性能。以下是关于Oracle 12c In-Memory特性的详细介绍: 一、基本概念 In-Memory Column Store&…...

【数据结构】二叉树———Lesson2
Hi~!这里是奋斗的小羊,很荣幸您能阅读我的文章,诚请评论指点,欢迎欢迎 ~~ 💥💥个人主页:奋斗的小羊 💥💥所属专栏:C语言 🚀本系列文章为个人学习…...

mongodb数据导出与导入
一、先去检查mongodump mongodump --version 如果报 mongodump version: built-without-version-string 或者其他的较老的版本,直接去下载最新的【传送门】 【以Ubuntu18.04为例】 安装工具 假设你下载的是 .tgz 文件(适用于 Linux 系统)&am…...

电路学习——经典运放电路之滞回比较器(施密特触发器)(2024.07.18)
参考链接1: 电子设计教程29:滞回比较器(施密特触发器) 参考链接2: 滞回比较器电路详细分析 参考链接3: 比较器精髓:施密特触发器,正反馈的妙用 参考链接4: 比较器反馈电阻选多大?理解滞后效应,轻…...

NVIDIA Container Toolkit 安装与配置帮助文档(Ubuntu,Docker)
NVIDIA Container Toolkit 安装与配置帮助文档(Ubuntu,Docker) 本文档详细介绍了在 Ubuntu Server 22.04 上使用 Docker 安装和配置 NVIDIA Container Toolkit 的过程。 概述 NVIDIA 容器工具包使用户能够构建和运行 GPU 加速容器。即可以在容器中使用NVIDIA显卡。 架构图如…...

JavaWeb day01-HTML入门
Web前端 课程安排 HTML、CSS简介 HTML快速入门 实现标题排版 新闻标题样式...

驱动框架——CMSIS第一部分 RTE驱动框架介绍
一、介绍CMISIS 什么是CMSIS(cortex microcontrol software interface standard一种软件标准接口),官网地址:https://arm-software.github.io/CMSIS_6/latest/General/index.html 包含的core、driver、RTOS、dsp、nn等部分&…...
Debezium日常分享系列之:Debezium2.7版本PostgreSQL数据库连接器
Debezium日常分享系列之:Debezium2.7版本PostgreSQL数据库连接器 一、概述二、连接器的工作原理安全快照初始快照的默认工作流程行为临时快照触发临时增量快照触发临时阻塞快照增量快照增量快照流程Debezium 如何解决具有相同主键的记录之间的冲突快照窗口触发增量快照具有附加…...
保障信息系统安全保护等级调整期间的安全性
保障信息系统安全保护等级调整期间的安全性: 策略与实践 在当今数字化时代,信息系统已成为企业和组织运营的核心支撑。为了适应不断变化的业务需求和安全威胁环境,信息系统安全保护等级的调整成为必要之举。然而,这一调整过程可能…...

实战:shell编程之全量命令练习
概叙 槽点~~~~~~~! 往期shell相关文章回顾,有兴趣的可以自行阅读和练习。 科普文:一文搞懂Vim-CSDN博客 科普文:jvm笔记-CSDN博客 科普文:一天学会shell编程-CSDN博客 科普文:Linux服务器巡检小结_lin…...
在 CentOS 7 上编译安装 Python 3.11
安装必要的依赖 首先,你需要安装一些开发工具和库,以便编译 Python 和 OpenSSL: yum -y groupinstall "Development tools" yum install -y wget gcc-c pcre pcre-devel zlib zlib-devel libffi-devel zlib1g-dev openssl-devel …...

Qt 4.8.7 + MSVC 中文乱码问题深入分析
此问题很常见,然而网上关于此问题的分析大多不够深刻,甚至有错误;加之Qt5又更改了一些编码策略,而很多文章并未提及版本问题,或是就算提了,读者也不重视。这些因素很容易让读者产生误导。今日我彻底研究透了…...

IDEA的常见代码模板的使用
《IDEA破解、配置、使用技巧与实战教程》系列文章目录 第一章 IDEA破解与HelloWorld的实战编写 第二章 IDEA的详细设置 第三章 IDEA的工程与模块管理 第四章 IDEA的常见代码模板的使用 第五章 IDEA中常用的快捷键 第六章 IDEA的断点调试(Debug) 第七章 …...

arcgis怎么选取某个指定区域地方的数据,比如从全国乡镇数据选取长沙市乡镇数据
一共5个步骤,没一句废话,耐心看完。看完你就会在任何软件选取指定范围的数据了。 一、如图,先将数据加载到arcgis里面,我们要选取里面长沙市的范围数据。 二、选取长沙市的语句 “市” like ‘长沙%’ 切记,切记&…...
二、链表(1)
203.移除链表元素 创建一个虚拟哨兵头节点,就不用考虑原本头结点要不要删除 # Definition for singly-linked list. # class ListNode: # def __init__(self, val0, nextNone): # self.val val # self.next next class Solution:def remove…...

KAFKA搭建教程
KAFKA搭建教程 期待您的关注 KAFKA学习笔记 帮助更多人 目录 KAFKA搭建教程 1.下载Kafka并解压 2.添加环境变量 3.修改 server.properties 文件 4.将kafka复制到其它节点 5.修改node1、node2节点的broker.id 6.将master的环境变量同步到node1、 node2 7.启动zookeeper…...

前端导出带有合并单元格的列表
// 导出async function exportExcel(fileName "共识调整.xlsx") {// 所有数据const exportData await getAllMainData();// 表头内容let fitstTitleList [];const secondTitleList [];allColumns.value.forEach(column > {if (!column.children) {fitstTitleL…...

【单片机期末】单片机系统设计
主要内容:系统状态机,系统时基,系统需求分析,系统构建,系统状态流图 一、题目要求 二、绘制系统状态流图 题目:根据上述描述绘制系统状态流图,注明状态转移条件及方向。 三、利用定时器产生时…...
css的定位(position)详解:相对定位 绝对定位 固定定位
在 CSS 中,元素的定位通过 position 属性控制,共有 5 种定位模式:static(静态定位)、relative(相对定位)、absolute(绝对定位)、fixed(固定定位)和…...

PL0语法,分析器实现!
简介 PL/0 是一种简单的编程语言,通常用于教学编译原理。它的语法结构清晰,功能包括常量定义、变量声明、过程(子程序)定义以及基本的控制结构(如条件语句和循环语句)。 PL/0 语法规范 PL/0 是一种教学用的小型编程语言,由 Niklaus Wirth 设计,用于展示编译原理的核…...
LLM基础1_语言模型如何处理文本
基于GitHub项目:https://github.com/datawhalechina/llms-from-scratch-cn 工具介绍 tiktoken:OpenAI开发的专业"分词器" torch:Facebook开发的强力计算引擎,相当于超级计算器 理解词嵌入:给词语画"…...

MySQL 8.0 OCP 英文题库解析(十三)
Oracle 为庆祝 MySQL 30 周年,截止到 2025.07.31 之前。所有人均可以免费考取原价245美元的MySQL OCP 认证。 从今天开始,将英文题库免费公布出来,并进行解析,帮助大家在一个月之内轻松通过OCP认证。 本期公布试题111~120 试题1…...

《基于Apache Flink的流处理》笔记
思维导图 1-3 章 4-7章 8-11 章 参考资料 源码: https://github.com/streaming-with-flink 博客 https://flink.apache.org/bloghttps://www.ververica.com/blog 聚会及会议 https://flink-forward.orghttps://www.meetup.com/topics/apache-flink https://n…...

IT供电系统绝缘监测及故障定位解决方案
随着新能源的快速发展,光伏电站、储能系统及充电设备已广泛应用于现代能源网络。在光伏领域,IT供电系统凭借其持续供电性好、安全性高等优势成为光伏首选,但在长期运行中,例如老化、潮湿、隐裂、机械损伤等问题会影响光伏板绝缘层…...
[Java恶补day16] 238.除自身以外数组的乘积
给你一个整数数组 nums,返回 数组 answer ,其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。 请 不要使用除法,且在 O(n) 时间复杂度…...
JavaScript基础-API 和 Web API
在学习JavaScript的过程中,理解API(应用程序接口)和Web API的概念及其应用是非常重要的。这些工具极大地扩展了JavaScript的功能,使得开发者能够创建出功能丰富、交互性强的Web应用程序。本文将深入探讨JavaScript中的API与Web AP…...