Python Pandas - 计算索引器并在没有完全匹配的情况下查找下一个索引值
要计算索引器并在没有完全匹配的情况下查找下一个索引值,请使用该方法。还将方法参数设置为bfill。index.get_indexer()
首先,导入所需的库-
import pandas as pd
创建熊猫索引-
index = pd.Index([10, 20, 30, 40, 50, 60, 70])
显示熊猫指数-
print("Pandas Index...\n",index)使用“get_indexer”计算索引器和掩码。如果没有完全匹配,请使用“方法”参数查找下一个索引值。该值设置为“bfill”-
print("\nGet the indexes...\n",index.get_indexer([30, 25, 58, 50, 55], method="bfill"))示例
以下是代码-
import pandas as pd
#创建Pandas索引
index = pd.Index([10, 20, 30, 40, 50, 60, 70])
#显示Pandas索引
print("Pandas Index...\n",index)
#返回索引中的元素数
print("\nNumber of elements in the index...\n",index.size)
# Compute indexer and mask using the "get_indexer"
# Find the next index value if no exact match using the "method" parameter.
# The value is set "bfill"
print("\nGet the indexes...\n",index.get_indexer([30, 25, 58, 50, 55], method="bfill"))输出结果这将产生以下输出-
Pandas Index... Int64Index([10, 20, 30, 40, 50, 60, 70], dtype='int64') Number of elements in the index... 7 Get the indexes... [2 2 5 4 5]
热门推荐
10 妈妈生日祝福语简短优美
11 新年祝福语鼠年简短创意
12 学生励志祝福语大全简短
13 对象打牌祝福语简短霸气
14 毕业写给学校简短祝福语
15 订婚酒刻字祝福语简短
16 鼠年元旦生日祝福语简短
17 送老师新春祝福语简短
18 初三新年祝福语简短