Dataframe column value handling problem

clipboard.png
the value in the type_pay column does not have a clear number of spaces, so the subsequent mapping processing is not successful. In order to achieve my mapping purpose, what should I do to reduce the type_pay column type value? Ask everyone for advice

Mar.02,2021

def tranf (x):

if x.startswith(('','','','','','','','')):
    x= 'a'
elif x.startswith(('','','')):
    x = 'b'
elif x.startswith(('','')):
    x = 'c'
elif x.startswith(('')):
    x = 'd' 
return x

train_order_later ['type_pay1'] = train_order_later [' type_pay']. Apply (tranf)
train_order_later ['type_pay1']. Value_counts ()

Menu