我将使用apply来解码列:
In [2]: animals = pd.Dataframe({"monkey":[0,1,0,0,0],"rabbit":[1,0,0,0,0],"fox":[0,0,1,0,0]})In [3]: def get_animal(row): ...: for c in animals.columns: ...: if row[c]==1: ...: return cIn [4]: animals.apply(get_animal, axis=1)Out[4]: 0 rabbit1 monkey2 fox3 None4 Nonedtype: object


