Python Pandas Index.max()

Python Pandas Index.max()

Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。

Pandas Index.max()函数返回索引的最大值。该函数既适用于数字型对象,也适用于字符串型对象。如果是字符串类型的对象,它将返回具有最高值的字符串,并按词典顺序排列。

语法: Index.max()

参数:不接受任何参数。

返回:标量。最大值。

例子#1:使用Index.max()函数来查找给定索引中的最大元素。

# importing pandas as pd
import pandas as pd
  
# Creating the Index
idx = pd.Index(['Labrador', 'Beagle', 'Mastiff', 'Lhasa', 'Husky', 'Beagle'])
  
# Print the Index
idx

输出 :
Python Pandas Index.max()

现在我们找到给定索引中的最大值。

# return max value.
idx.max()

输出 :
Python Pandas Index.max()
正如我们在输出中看到的,该函数返回了’Mastiff’,它在索引中的数值中具有最高的词序。

例子#2:使用Index.max()函数来查找索引中的最大值。

# importing pandas as pd
import pandas as pd
  
# Creating the Index
idx = pd.Index([17, 69, 33, 5, 0, 74, 0])
  
# Print the Datetime Index
idx

输出 :
Python Pandas Index.max()

现在我们将在索引的标签中找到最大值。

# the function will return the
# maximum value present in the Index
idx.max()

输出 :
Python Pandas Index.max()

正如我们在输出中看到的,该函数返回了74,这是该索引的标签中最大的值。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程