This question already has answers here:
Is there a simple way to change a column of yes/no to 1/0 in a Pandas dataframe?
                                
                                    (12个答案)
                                
                        
                                2年前关闭。
            
                    
如何在Pandas DataFrame中将“是”或“否”更改为0或1?

最佳答案

也许:

>>> df=pd.DataFrame({'a':['yes','no','yes'],'b':['no','no','yes']})
>>> df.apply(lambda x: x.map({'yes':1,'no':0}),axis=0)
   a  b
0  1  0
1  0  0
2  1  1

关于python - 如何将是或否更改为二进制分类? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51959484/

10-15 18:30