i have couple columns in data frame that contains numeric values and string
and i want to remove all characters and leave only numbers
Admit_DX_Description Primary_DX_Description
510.9 - EMPYEMA W/O FISTULA 510.9 - EMPYEMA W/O FISTULA
681.10 - CELLULITIS, TOE NOS 681.10 - CELLULITIS, TOE NOS
780.2 - SYNCOPE AND COLLAPSE 427.89 - CARDIAC DYSRHYTHMIAS NEC
729.5 - PAIN IN LIMB 998.30 - DISRUPTION OF WOUND, UNSPEC
to
Admit_DX_Description Primary_DX_Description
510.9 510.9
681.10 681.10
780.2 427.89
729.5 998.30
code:
for col in strip_col:
# # Encoding only categorical variables
if df[col].dtypes =='object':
df[col] = df[col].map(lambda x: x.rstrip(r'[a-zA-Z]'))
print df.head()
error:
Traceback (most recent call last):
df[col] = df[col].map(lambda x: x.rstrip(r'[a-zA-Z]'))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/series.py", line 2175, in map new_values = map_f(values, arg) File "pandas/src/inference.pyx", line 1217, in pandas.lib.map_infer (pandas/lib.c:63307)
df[col] = df[col].map(lambda x: x.rstrip(r'[a-zA-Z]'))
AttributeError: 'int' object has no attribute 'rstrip'