Question: I have three columns in a pandas dataframe that I want to convert into a single date column. The problem is that one of the columns is day column. I am not able to convert into exact date of that month and year. Can anyone please help me to solve this issue. It looks something like this:

```
   BirthMonth BirthYear Day
0   5           88      1st Monday
1   10          87      3rd Tuesday
2   12          87      2nd Saturday
3   1           88      1st Tuesday
4   2           88      1st Monday

```

Answer: 
Based on your reply to my first comment I updated my answer as follows. I think this is what you are looking for:

```
import re
import time
import calendar
import numpy as np

days = ['1st Monday', '3rd Tuesday', '4th wednesday']
months = [2, 3, 5]
years = [1990, 2000, 2019]

def extract_numeric(text: str):
    return int(re.findall(r'\d+', text)[0])

def weekday_to_number(weekday: str):
    return time.strptime(weekday, "%A").tm_wday

def get_date(number: int, weekday: int, month: int, year: int) -> str:
    """ 3rd Tuesday translates to number: 3, weekday: 1 """
    firstday, n_days = calendar.monthrange(year, month)
    day_list = list(range(7)) * 6
    month_days = day_list[firstday:][:n_days]
    day = (np.where(np.array(month_days) == weekday)[0] + 1)[number - 1]
    return '{}/{}/{}'.format(day, month, year)

numbers = []
weekdays = []
for day in days:
    number, weekday = day.split()
    numbers.append(extract_numeric(number))
    weekdays.append(weekday_to_number(weekday))

dates = []
for number, weekday, month, year in zip(numbers, weekdays, months, years):
    dates.append(get_date(number, weekday, month, year))

print(dates)  # ['5/2/1990', '21/3/2000', '22/5/2019']

```
use the calendar module to get the `day` from days. then convert `day,monyh,year` to `DateTime`

```
import calendar
import datetime
def get_date(rows):
    day = {'monday':0,'tuesday':1,'wednesday':2,'thursday':3,'friday':4,'saturday':5,'sunday':6}
    day_num = day.get(rows.days.split()[1].lower())
    weekday_num = [week[day_num] for week in calendar.monthcalendar(rows.years, rows.months) if week[day_num] >0][int(rows.days.split()[0][0])-1]
    return datetime.date(rows.years, rows.months, weekday_num)

```

apply the above function to all rows

```
df['date'] = df(lambda row: get_date(row), axis=1)
df
>>
          days   months  years  date
0   1st Monday        8  2015   2015-08-03
1   3rd Tuesday      12  2017   2017-12-19
2   4th wednesday     5  2019   2019-05-22

```