-3
ID Duration 
0   6-month
1   12-month
2   24-month

I want to delete '-month'. Can you help me ?

Thanks

Laura
  • 1
  • 1

2 Answers2

0

Assuming that month number comes before the '-month' in duration

You can use regex to extract the digits.

df['Duration']=df['Duration'].str.extract(r'(\d*)')
df
    ID  Duration
0    0       6
1    1      12
2    2      24
Naveed
  • 11,495
  • 2
  • 14
  • 21
0

Here's another solution

df['Duration']= df['Duration'].apply(lambda x:x.replace('-month',''))