Python Pandas - 计算与给定标签相对应的左切片边界
要计算与给定标签相对应的左切片边界,请使用index.get_slice_bound()。将side参数设置为left。
首先,导入所需的库 -
import pandas as pd
创建 Pandas 索引 -
index = pd.Index([10, 20, 30, 40, 50, 60, 70])
显示 Pandas 索引 -
print("Pandas Index...\n",index)获取左切片边界。如果“side”参数设置为“left”,则返回给定标签的左切片边界
print("\nGet the left slice bound...\n",index.get_slice_bound(30, side='left', kind ='getitem'))
示例
以下是代码 -
import pandas as pd
# Creating Pandas index
index = pd.Index([10, 20, 30, 40, 50, 60, 70])
# Display the Pandas index
print("Pandas Index...\n",index)
# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index.size)
# Get the left slice bound
# Returns the left slice bound of given label if "side" parameter is set to "left"
print("\nGet the left slice bound...\n", index.get_slice_bound(30, side='left', kind ='getitem'))输出
这将生成以下输出 -
Pandas Index... Int64Index([10, 20, 30, 40, 50, 60, 70], dtype='int64') Number of elements in the index... 7 Get the left slice bound... 2
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP