I want to clean one column of my df['emp_length'] [shown in the screen shot]1
but when I use
df_10v['emp_length'] = df_10v['emp_length'].map(lambda x: x.lstrip('<').rstrip('+'))
to remove thing i dont want. It gave me an error:
'float' object has no attribute 'lstrip'
However, the type shows object instead of float. I tried .remove too but gave me the same error. I also tried
df['column'] = df['column'].astype('str')
to change df_10v['emp_length'] in to string and then strip, but it does not work either. Anybody know how to solve this? Thank you!
UPDATE: removing all non-digits:
df_10v['emp_length'] = df_10v['emp_length'].astype(str).str.replace('\D+', '')
old answer:
IIUC:
df_10v['emp_length'] = df_10v['emp_length'].astype(str).str.lstrip('<').str.rstrip('+')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With