Python 如何提取ID';数据帧中一列中前两个值的大小?
我有一个dataframe,从中需要特定列的前两个值的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分配给输出
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')