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']

```
Not very fast solution(since it involves 2 nested loops) but I hope this solves your question

```
import pandas as pd
import datetime
import calendar

pd.set_option('display.max_rows', 100)

cols = ['day', 'month', 'year']

data = [
    ['1st Monday', 8, 2015],
    ['3rd Tuesday', 12, 2017],
    ['4th Wednesday', 5, 2019]
]

df = pd.DataFrame(data=data, columns=cols)
df['week_number'] = df['day'].str.slice(0, 1)
df['week_number'] = df['week_number'].astype('int')
df['day_name'] = df['day'].str.slice(4)

def generate_dates(input_df, index_num):
    _, days = calendar.monthrange(input_df.loc[index_num, 'year'], input_df.loc[index_num, 'month'])
    df_dates = pd.DataFrame()
    for i in range(1, days + 1):
        df_dates.loc[i - 1, 'date'] = datetime.date(input_df.loc[index_num, 'year'], input_df.loc[index_num, 'month'],
                                                    i)
        df_dates.loc[i - 1, 'year'] = input_df.loc[index_num, 'year']
        df_dates.loc[i - 1, 'days'] = calendar.weekday(input_df.loc[index_num, 'year'],
                                                       input_df.loc[index_num, 'month'], i)
        df_dates.loc[i - 1, 'day_name'] = df_dates.loc[i - 1, 'date'].strftime("%A")

    df_dates['week_number'] = 1
    df_dates['week_number'] = df_dates.groupby('day_name')['week_number'].cumsum()
    return df_dates

dates = pd.DataFrame(columns=['date', 'year', 'days', 'day_name', 'week_number'])
for row in df.index:
    dates = pd.concat([dates, generate_dates(df, row)])

df2 = df.merge(dates, on=['year', 'day_name', 'week_number'])

print(df2)

```