assume df as;
data = {'duration':['1week 3day 2hour 4min 23', '2hour 4min 23sec', '2hour 4min', np.nan, '', '23sec']}
df = pd.DataFrame(data)
I'm trying to calculate the duration as sum of seconds. Replaced the values as:
df['duration'] = df['duration'].str.replace('week', '*604800+') \
.str.replace('day', '*604800+') \
.str.replace('hour', '*3600+') \
.str.replace('min', '*60+') \
.str.replace('sec', '') \
.str.replace(' ', '')
But cant run eval functions like (pd.eval, apply.eval, eval etc). Some cells ends with '+' sign or other string/na problems.. Any help?
Ps: This is not a duplicate question.