小编PYB*_*PYB的帖子

获取字符串时列中的索引最小值 - Pandas Dataframe

我对此进行了一些研究,但是当索引为“字符串”类型时找不到简洁的方法。

给定以下 Pandas 数据框:

Platform | Action |    RPG    | Fighting
----------------------------------------
PC       |   4    |      6    |     9
Playstat |   6    |      7    |     5
Xbox     |   9    |      4    |     6
Wii      |   8    |      8    |     7
Run Code Online (Sandbox Code Playgroud)

我试图获取“RPG”列中最小值的索引(平台),这将返回“Xbox”。我设法让它工作,但效率不高,正在寻找更好/更快/更简洁的方法。这是我得到的:

# Return the minimum value of a series of all columns values for RPG
series1 = min(ign_data.loc['RPG'])

# Find the lowest value in the series
minim = min(ign_data.loc['RPG'])

# Get the index of that value using boolean indexing
result …
Run Code Online (Sandbox Code Playgroud)

python indexing series dataframe pandas

3
推荐指数
1
解决办法
1448
查看次数

标签 统计

dataframe ×1

indexing ×1

pandas ×1

python ×1

series ×1