我讀了一個csv文件到一個熊貓數據框中,並且想用二進制答案將字符串轉換爲1/0的整數。下面,我展示了其中一個這樣的列(「sampleDF」是熊貓數據框)。是否有一種簡單的方法可以將Pandas數據框中的一列是/否更改爲1/0?
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(( '是', '否'),(1,0),就地= TRUE)' – AChampion
,沒有工作,謝謝! – Mushu909