天涯尽头无女友
使用ilocwith boolean indexing,为了性能更好,index不过滤DataFrame然后选择索引(请参阅性能):df = pd.DataFrame({ 'A':list('abcdef'), 'B':[4,5,4,5,5,4], 'C':[7,8,9,4,2,3], 'D':[1,3,5,7,1,0], 'E':[5,3,6,9,2,4], 'F':list('aaabbb')})print (df) A B C D E F0 a 4 7 1 5 a1 b 5 8 3 3 a2 c 4 9 5 6 a3 d 5 4 7 9 b4 e 5 2 1 2 b5 f 4 3 0 4 bs = df.iloc[0] a = s.index[s == 1]print (a)Index(['D'], dtype='object')a = s.index.values[(s == 1)]print (a)['D']