you can use np.select. In order to check the length of the string, you have to first make sure that the column's format is a string, hence .astype(str). Then, you can use .apply(lambda x: len(x) == condition) to to return a result based on the condition:
import numpy as np
input_file['cusotmerid'] = input_file['cusotmerid'].astype(str)
input_file['cusotmerid'] = np.select([input_file['cusotmerid'].apply(lambda x: len(x) == 8),
input_file['cusotmerid'].apply(lambda x: len(x) == 9)],
[input_file['cusotmerid'].str[0:2] + '-' + input_file['cusotmerid'].str[2:8],
'K' + '-' + input_file['cusotmerid'].str[0:3] + '-' + input_file['cusotmerid'].str[3:9]],
input_file['cusotmerid'])
input_file
id cusotmerid
0 1 89-898988
1 2 K-898-989889
It may be easier to break the np.select statement down into conditions and results. The 3 parameters I pass are conditions, results, and default value if no conditions are met.
input_file['cusotmerid'] = input_file['cusotmerid'].astype(str)
c1 = input_file['cusotmerid'].apply(lambda x: len(x) == 8)
c2 = input_file['cusotmerid'].apply(lambda x: len(x) == 9)
conditions = [c1, c2]
r1 = input_file['cusotmerid'].str[0:2] + '-' + input_file['cusotmerid'].str[2:8]
r2 = 'K' + '-' + input_file['cusotmerid'].str[0:3] + '-' + input_file['cusotmerid'].str[3:9]
results = [r1,r2]
input_file['cusotmerid'] = np.select(conditions, results, input_file['cusotmerid'])
input_file
id cusotmerid
0 1 89-898988
1 2 K-898-989889