gpt4 book ai didi

python - Pandas DataFrame 从列中检索值

转载 作者:太空狗 更新时间:2023-10-30 03:03:27 26 4
gpt4 key购买 nike

假设我有如下数据框:

Idx A B C
0 1 2 3
1 3 4 5
2 2 3 8

dataframe 列 B 的最大值是 4,我可以从 df["B"].argmax() 得到索引,它是 1。

现在的问题是,我怎样才能得到数据框 B 列的确切最大值?

谢谢!

最佳答案

In [6]: df
Out[6]:
A B C
Idx
0 1 2 3
1 3 4 5
2 2 3 8

In [7]: df.max()
Out[7]:
A 3
B 4
C 8
dtype: int64

In [10]: df['B'].max()
Out[10]: 4

In [8]: df.idxmax()
Out[8]:
A 1
B 1
C 2
dtype: int64

关于python - Pandas DataFrame 从列中检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18945384/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com