-3

I have a column in a dataframe named 'term'. its value is ('36 months', '60 months', '36 months', '36 months', '60 months') Now I want to convert that column to numeric like (36,60,36,36,60) How can I do that?

Bigkfish
  • 111
  • 1
  • 2
  • 4

1 Answers1

1

This might help:

In [12]: df 
Out[12]: 
        term
0  36 months
1  60 months
2  36 months
3  36 months
4  60 months

In [14]: df.term.str.replace(' months','').astype(int)
Out[14]: 
0    36
1    60
2    36
3    36
4    60
Name: term, dtype: int64
Mohamed Ali JAMAOUI
  • 14,275
  • 14
  • 73
  • 117