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 5Question: 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!
更多推荐
发布评论