Python:比较pandas dataframe中的两个值并获取最小值的索引(Python: Compare two values in pandas dataframe and get index

系统教程 行业动态 更新时间:2024-06-14 16:57:40
Python:比较pandas dataframe中的两个值并获取最小值的索引(Python: Compare two values in pandas dataframe and get index of minimum value)

我的熊猫数据帧:

In [11]: dframe = pd.DataFrame({"A":list("abcde"), "B":list("fghij"), "C":[1,2,3,4,5]}, index=[10,11,12,13,14]) Out[11]: A B C 10 a f 1 11 b g 2 12 c h 3 13 d i 4 14 e j 5

问题:比较第一行(1)和第二行(第二行)的“C”列中的值,得到最小值的索引? 答案:10

My pandas dataframe:

In [11]: dframe = pd.DataFrame({"A":list("abcde"), "B":list("fghij"), "C":[1,2,3,4,5]}, index=[10,11,12,13,14]) Out[11]: A B C 10 a f 1 11 b g 2 12 c h 3 13 d i 4 14 e j 5

Question: Compare values in 'C' column of first (1) and second (2) row and get index of minimum? Answer: 10

最满意答案

尝试这个:

dframe[0:2]['C'].idxmin()

我希望这有帮助!

Try this:

dframe[0:2]['C'].idxmin()

I hope this helps!

更多推荐

本文发布于:2023-04-13 12:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/dec8611cc31f4026dbe75c2d62496384.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   最小值   两个   dataframe   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!