找到 10786 篇文章 关于 Python

Python Pandas - 根据当前索引计算新索引的索引器和掩码

AmitDiwan
更新于 2021年10月14日 07:48:13

80 次浏览

要根据当前索引计算新索引的索引器和掩码,请在 Pandas 中使用 index.get_indexer() 方法。首先,导入所需的库 −import pandas as pd 创建 Pandas 索引 −index = pd.Index([10, 20, 30, 40, 50, 60, 70]) 显示 Pandas 索引 −print("Pandas 索引...", index) 计算索引器和掩码。标记为 -1,因为它不在索引中 −print("获取索引...", index.get_indexer([30, 40, 90, 100, 50])) 示例以下是代码 −import pandas as pd # 创建 Pandas 索引 index = pd.Index([10, 20, 30, 40, 50, 60, 70]) # 显示 Pandas 索引 print("Pandas 索引...", index) # 返回 ... 阅读更多

Python Pandas - 如果索引中的所有标签都晚于传递的标签,则返回索引中的标签

AmitDiwan
更新于 2021年10月14日 07:30:41

85 次浏览

如果索引中的所有标签都晚于传递的标签,则要返回索引中的标签,请在 Pandas 中使用 index.asof() 方法。首先,导入所需的库 −import pandas as pd 创建 Pandas 索引 −index = pd.Index([10, 20, 30, 40, 50, 60, 70]) 显示 Pandas 索引 −print("Pandas 索引...", index) 返回索引中的标签。如果索引中的所有标签都晚于传递的标签,则返回 NaN −print("从索引中获取标签...", index.asof(6)) 示例以下是代码 −import pandas as pd # 创建 Pandas 索引 index = pd.Index([10, 20, ... 阅读更多

Python Pandas - 返回索引中的标签,如果不存在,则返回前一个标签

AmitDiwan
更新于 2021年10月14日 07:28:50

219 次浏览

要返回索引中的标签,如果不存在,则返回前一个标签,请在 Pandas 中使用 index.asof() 方法。首先,导入所需的库 −import pandas as pd 创建 Pandas 索引 −index = pd.Index([10, 20, 30, 40, 50, 60, 70]) 显示 Pandas 索引 −print("Pandas 索引...", index) 返回索引中的标签,如果不存在,则返回前一个标签 −print("从索引中获取标签...", index.asof(43)) 示例以下是代码 −import pandas as pd # 创建 Pandas 索引 index = pd.Index([10, 20, 30, 40, 50, 60, 70]) # 显示 Pandas 索引 print("Pandas 索引...", index) # 返回 ... 阅读更多

Python Pandas - 判断两个顺序相反的索引对象是否相等

AmitDiwan
更新于 2021年10月14日 07:27:40

120 次浏览

要判断两个顺序相反的索引对象是否相等,请使用 equals() 方法。首先,导入所需的库 −import pandas as pd 创建 Pandas index1 和 index2 −index1 = pd.Index([15, 25, 35, 45, 55, 65, 75, 85, 95]) index2 = pd.Index([95, 85, 75, 65, 55, 45, 35, 25, 15]) 显示 index1 和 index2 −print("Pandas Index1...", index1) print("Pandas Index2...", index2) 检查两个顺序相反的索引对象是否相等 −print("两个顺序相反的索引对象是否相等?", index1.equals(index2)) 示例以下是代码 −import pandas as pd # 创建 Pandas index1 和 index2 index1 = pd.Index([15, 25, ... 阅读更多

Python Pandas - 判断两个索引对象是否相等

AmitDiwan
更新于 2021年10月14日 07:25:49

912 次浏览

要判断两个索引对象是否相等,请使用 equals() 方法。首先,导入所需的库 −import pandas as pd 创建 index1 和 index2 −index1 = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) index2 = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) 显示 index1 和 index2 −print("Pandas Index1...", index1) print("Pandas Index2...", index2) 检查两个索引对象是否相等 −index1.equals(index2) 示例以下是代码 −import pandas as pd # 创建 index1 和 index2 index1 = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) index2 = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) ... 阅读更多

Python Pandas - 计算两个索引对象的对称差集并取消排序结果

AmitDiwan
更新于 2021年10月14日 07:26:44

145 次浏览

要计算两个索引对象的对称差集并取消排序结果,请在 Pandas 中使用 symmetric_difference() 方法。要取消排序,请使用 sort 参数并将其设置为 False。首先,导入所需的库 −import pandas as pd 创建两个 Pandas 索引 −index1 = pd.Index([50, 30, 20, 40, 10]) index2 = pd.Index([40, 10, 60, 20, 55]) 显示 Pandas index1 和 index2 −print("Pandas Index1...", index1) print("Pandas Index2...", index2) 执行对称差集。使用值为 False 的“sort”参数取消排序结果 −res = index1.symmetric_difference(index2, sort=False) 示例以下是代码 −import pandas as pd # 创建两个 Pandas 索引 index1 = pd.Index([50, 30, ... 阅读更多

Python Pandas - 计算两个索引对象的对称差集

AmitDiwan
更新于 2021年10月14日 07:23:25

420 次浏览

要计算两个索引对象的对称差集,请在 Pandas 中使用 index1.symmetric_difference(index2) 方法。首先,导入所需的库 −import pandas as pd 创建两个 Pandas 索引 −index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index([40, 10, 60, 20, 55]) 显示 Pandas index1 和 index2 −print("Pandas Index1...", index1) print("Pandas Index2...", index2) 执行对称差集 −res = index1.symmetric_difference(index2) 示例以下是代码 −import pandas as pd # 创建两个 Pandas 索引 index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index([40, 10, 60, 20, 55]) # 显示 Pandas index1 和 index2 print("Pandas Index1...", index1) print("Pandas Index2...", index2) ... 阅读更多

Python Pandas - 返回一个新索引,其中包含 index 中不在 other 中的元素,但取消排序结果

AmitDiwan
更新于 2021年10月14日 07:21:28

101 次浏览

要返回一个新索引,其中包含 index 中不在 other 中的元素,但取消排序结果,请使用 difference() 方法。将 sort 参数设置为 False。首先,导入所需的库 −import pandas as pd 创建两个 Pandas 索引 −index1 = pd.Index([30, 10, 20, 50, 40]) index2 = pd.Index([80, 40, 60, 20, 55]) 显示 Pandas index1 和 index2 −print("Pandas Index1...", index1) print("Pandas Index2...", index2) 获取两个索引的差集。使用值为“False”的“sort”参数取消排序结果 −res = index1.difference(index2, sort=False) 示例以下是代码 −import pandas as pd # 创建两个 Pandas 索引 index1 = pd.Index([30, ... 阅读更多

Python Pandas - 返回一个新索引,其中包含 index 中不在 other 中的元素,并获取差集

AmitDiwan
更新于 2021年10月14日 07:19:39

244 次浏览

要返回一个新的Index,其中包含index中不在other中的元素并获取差集,请使用Pandas中的index1.difference(index2)方法。首先,导入所需的库 − import pandas as pd 创建两个Pandas索引 − index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index([80, 40, 60, 20, 55]) 显示Pandas索引1和索引2 print("Pandas Index1...", index1) print("Pandas Index2...", index2) 获取两个索引的差集 − res = index1.difference(index2) 示例以下为代码 − import pandas as pd # 创建两个Pandas索引 index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index([80, 40, 60, 20, 55]) # 显示Pandas ... 阅读更多

Python Pandas - 形成两个不同数据类型索引对象的并集

AmitDiwan
更新于 2021年10月14日 07:16:14

308 次浏览

要形成两个不同数据类型索引对象的并集,请使用Pandas中的index1.union(index2)方法。首先,导入所需的库 − import pandas as pd 创建两个Pandas索引 − index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index(['p', 'q', 'r', 's', 't', 'u']) 显示Pandas索引1和索引2 − print("Pandas Index1...", index1) print("Pandas Index2...", index2) 执行不匹配数据类型的并集 − res = index1.union(index2) 示例以下为代码 − import pandas as pd # 创建两个Pandas索引 index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index(['p', 'q', 'r', 's', 't', 'u']) # 显示Pandas索引1和索引2 print("Pandas ... 阅读更多

广告
© . All rights reserved.