Python - 返回 Pandas 指数的最小值

pythonserver side programmingprogramming更新于 2025/12/28 20:28:17

要返回 Pandas 指数的最小值,请使用 index.min() 方法。首先,导入所需的库 -

import pandas as pd

创建 Pandas 索引 −

index = pd.Index([10.5, 20.4, 40.5, 25.6, 5.7, 6.8, 30.8, 50.2])

显示 Pandas 索引 −

print("Pandas Index...\n",index)

获取最小值 −

print("\n最小值..\n", index.min())

示例

以下是代码 −

import pandas as pd

# 创建 Pandas 索引
index = pd.Index([10.5, 20.4, 40.5, 25.6, 5.7, 6.8, 30.8, 50.2])

# 显示 Pandas 索引
print("Pandas Index...\n",index)

# 返回索引中的元素数量
print("\n索引中的元素数量...\n",index.size)

# 返回数据的 dtype
print("\ndtype对象...\n",index.dtype)

# 获取最小值
print("\n最小值..\n", index.min())

输出

这将产生以下输出 −

Pandas Index...
Float64Index([10.5, 20.4, 40.5, 25.6, 5.7, 6.8, 30.8, 50.2], dtype='float64')

索引中的元素数量...
8

dtype 对象...
float64

最小值..
5.7

相关文章


有用资源