Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何提取ID';数据帧中一列中前两个值的大小?_Python_Pandas_Dataframe - Fatal编程技术网

Python 如何提取ID';数据帧中一列中前两个值的大小?

Python 如何提取ID';数据帧中一列中前两个值的大小?,python,pandas,dataframe,Python,Pandas,Dataframe,我有一个dataframe,从中需要特定列的前两个值的ID(索引值) 范例 two_highest_degree_id=karate.nlargest(2,'degree') 空手道是我的数据帧,我需要列度的前两个值的索引值。上面的脚本给了我以下结果: club degree cluster_coef 33 Officer 17 0.110294 0 Mr. Hi 16 0.150000 如何将索引值33,&0分配给输出

我有一个dataframe,从中需要特定列的前两个值的ID(索引值)

范例

two_highest_degree_id=karate.nlargest(2,'degree')
空手道是我的数据帧,我需要列度的前两个值的索引值。上面的脚本给了我以下结果:

      club     degree  cluster_coef
33  Officer      17      0.110294
0    Mr. Hi      16      0.150000
如何将索引值
33
,&
0
分配给输出

import pandas as pd
df = pd.DataFrame([10,9,8,7,6,50], columns = ['degree'])

df.nlargest(2,'degree').index
#op
Int64Index([5, 0], dtype='int64')