我将一个csv文件读入pandas dataframe中,并希望将二元回答的列从yes/no字符串转换为1/0整数。下面是其中一列的示例("sampleDF"是pandas dataframe)。
In [13]: sampleDF.housing[0:10]
Out[13]:
0 no
1 no
2 yes
3 no
4 no
5 no
6 no
7 no
8 yes
9 yes
Name: housing, dtype: object
非常感谢您的帮助!
sampleDF.housing.replace(('yes', 'no'), (1, 0), inplace=True)
- AChampion