I am not very knowledgeable in pandas
So I have a problem which is the following :
I want to get the number of days based on string column
Period
3 days
5 weeks
1 year
I want to convert this column into an integer which is the number of days like this:
Days
3
35
365
I have done as follow:
def toDays(dt):
if 'year' in dt:
for s in dt:
if s.isdigit():
return int(s)*360
elif 'month' in dt:
for s in dt:
if s.isdigit():
return int(s)*30
elif 'week' in dt:
for s in dt:
if s.isdigit():
return int(s)*7
if 'day' in dt:
for s in dt:
if s.isdigit():
return int(s)
train_file["Days"]=train_file["Periods"].map(toDays)
but that didn't work I would some help in order to map this function into the dataframe