Código
def clean_code(text):
text = str(text)
parent_code = None
if len(text) == 12:
code = text[:5]
parent_code = text[:1]
else:
code = text[:6]
parent_code = text[:2]
try:
parent = df_parents[df_parents['Code_comm'] == parent_code]['Description'].values[0]
except:
parent = None
return (code, parent)
df_codes[['clean_code', 'parent_description']] =
df_codes.apply(
lambda x: clean_code( x['Code'] ),
axis=1,
result_type='expand'
)
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?