Pandas DataFrame.idxmax()函数
Python Pandas DataFrame.idxmax() 函数返回行或列中最大值的索引。
pandas.DataFrame.idxmax()
的语法
DataFrame.idxmax(axis=0, skipna=True)
参数
axis |
它是一个整数或字符串类型的参数。它指定要使用的轴。0 或 index 代表行,1 或 columns 代表列。 |
skipna |
它是一个布尔参数。这个参数指定排除空值。如果整行或整列都是空值,结果将是 NA。 |
返回值
它返回一个 Series
,代表沿指定轴的最大值的索引。
示例代码: DataFrame.idxmax()
按行查找最大数值索引
import pandas as pd
dataframe=pd.DataFrame({'Attendance': {0: 60, 1: 100, 2: 80,3: 78,4: 95},
'Obtained Marks': {0: 90, 1: 75, 2: 82, 3: 64, 4: 45}})
print("The Original Data frame is: \n")
print(dataframe)
series = dataframe.idxmax()
print("The Indexes are: \n")
print(series)
输出:
The Original Data frame is:
Attendance Obtained Marks
0 60 90
1 100 75
2 80 82
3 78 64
4 95 45
The Indexes are:
Attendance 1
Obtained Marks 0
dtype: int64
函数返回最大 Attendance
和 Obtained Marks
的索引。
示例代码:DataFrame.idxmax()
按列查找最大值索引
import pandas as pd
dataframe=pd.DataFrame({'Attendance': {0: 60, 1: 100, 2: 80,3: 78,4: 95},
'Obtained Marks': {0: 90, 1: 75, 2: 82, 3: 64, 4: 45}})
print("The Original Data frame is: \n")
print(dataframe)
series = dataframe.idxmax(axis= 1)
print("The Indexes are: \n")
print(series)
输出:
The Original Data frame is:
Attendance Obtained Marks
0 60 90
1 100 75
2 80 82
3 78 64
4 95 45
The Indexes are:
0 Obtained Marks
1 Attendance
2 Obtained Marks
3 Attendance
4 Attendance
dtype: object
该函数按列返回索引。
相关文章
Pandas DataFrame DataFrame.shift() 函数
发布时间:2024/04/24 浏览次数:133 分类:Python
-
DataFrame.shift() 函数是将 DataFrame 的索引按指定的周期数进行移位。
Python pandas.pivot_table() 函数
发布时间:2024/04/24 浏览次数:82 分类:Python
-
Python Pandas pivot_table()函数通过对数据进行汇总,避免了数据的重复。
Pandas read_csv()函数
发布时间:2024/04/24 浏览次数:254 分类:Python
-
Pandas read_csv()函数将指定的逗号分隔值(csv)文件读取到 DataFrame 中。
Pandas 多列合并
发布时间:2024/04/24 浏览次数:628 分类:Python
-
本教程介绍了如何在 Pandas 中使用 DataFrame.merge()方法合并两个 DataFrames。
Pandas loc vs iloc
发布时间:2024/04/24 浏览次数:837 分类:Python
-
本教程介绍了如何使用 Python 中的 loc 和 iloc 从 Pandas DataFrame 中过滤数据。
在 Python 中将 Pandas 系列的日期时间转换为字符串
发布时间:2024/04/24 浏览次数:894 分类:Python
-
了解如何在 Python 中将 Pandas 系列日期时间转换为字符串