为什么此代码 (if-elif) 语句在 python (jupyter notebook?

时间:2021-02-24 03:49:04

标签: python pandas if-statement converters

def convert_AGE_RANGE_CID_cell(cell):
    if cell=="0-17":
        return '1'
    return cell
    elif cell==18-25:
        return '2'
    elif cell==26-35:
        return '3'
    elif cell==36-45:
        return '4'
    elif cell==46+:
        return '5'
    
    return cell

 'AGE_RANGE_CID': convert_AGE_RANGE_CID_cell,

1 个答案:

答案 0 :(得分:0)

你不能这样做:

elif cell==46+:
   something here

如果你想比较单元格是否大于 46,那么你应该这样做:

elif cell => 46:
    do_something