Python - 返回 Pandas 索引的最大值
pythonserver side programmingprogramming更新于 2025/12/28 22:04:17
要返回 Pandas 索引的最大值,请使用 index.max() 方法。首先,导入所需的库 -
import pandas as pd
创建 Pandas 索引
index = pd.Index([10, 20, 70, 40, 90, 50, 25, 30])
显示 Pandas 索引 −
print("Pandas Index...\n",index)
获取最大值 −
print("\n最大值..\n", index.max())
示例
以下是代码 −
import pandas as pd
# 创建 Pandas 索引
index = pd.Index([10, 20, 70, 40, 90, 50, 25, 30])
# 显示 Pandas 索引
print("Pandas Index...\n",index)
# 返回 Index 中的元素数量
print("\n索引中的元素数量...\n",index.size)
# 返回数据的 dtype
print("\ndtype 对象...\n",index.dtype)
# 获取最大值
print("\n最大值..\n",索引.max()
输出
这将产生以下输出 −
Pandas Index... Int64Index([10, 20, 70, 40, 90, 50, 25, 30], dtype='int64') 索引中的元素数量... 8 dtype 对象... int64 最大值.. 90
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

