1
我試圖創建一個新列,而不是使用當前列的現有值,但使用新值。我繼續並創建了一個函數來執行此操作,但是,我收到一個錯誤消息。我要的結果是每個市有IE瀏覽器= 1,SC = 2等如何在python&pandas中創建新列
def ET(ET):
return "ET" == 1
def TO(TO):
return "TO" == 2
def NY(NY):
return "NY" == 3
def SC(SC):
return "SC" == 4
def coded_municipality(row):
if row['coded_municipality'] == "ET" :
return 1
if row['coded_municipality'] == "NY" :
return 2
if row['coded_municipality'] == "SC" :
return 3
if row['coded_municipality'] == "TO" :
return 4
marriage_data['Code'] = marriage_data.apply(lambda row : coded_municipality(row),axis=1)
但是一個碼數,我仍然得到一個錯誤說「coded_municipality」,「在指數發生0」
我做錯了什麼?