看到只有一行,那么您可以调用
iloc[0]结果并使用它来屏蔽列:
In [47]:df.columns[(df == 38.15).iloc[0]]Out[47]:Index(['col7'], dtype='object')
分解以上内容:
In [48]:df == 38.15Out[48]: Date col1 col2 col3 col4 col5 col6 col701/01/2016 False False False False False False False TrueIn [49]:(df == 38.15).iloc[0]Out[49]:Date Falsecol1 Falsecol2 Falsecol3 Falsecol4 Falsecol5 Falsecol6 Falsecol7 TrueName: 01/01/2016, dtype: bool
您也可以使用
idxmaxparam
axis=1:
In [52]:(df == 38.15).idxmax(axis=1)[0]Out[52]:'col7'



