# Create the DataFrame
data = {
'id_number': ['000001000', '000009795', '000011722'],
'first_date': ['2022-01-08 13:41:00', '2022-11-07 09:16:00', '2022-02-15 12:46:00'],
'last_date': ['2023-06-13 16:33:00', '2022-11-30 12:59:00', '2022-06-21 11:42:00']
}
df_test = pd.DataFrame(data)
# Convert date columns to datetime
df_test['first_date'] = pd.to_datetime(df_test['first_date'])
df_test['last_date'] = pd.to_datetime(df_test['last_date'])
# Calculate difference in months based on days
df_test['months_difference'] = ((df_test['last_date'] - df_test['first_date']).dt.days) // 30.44
#30.44 is avg of days per month in a non-leap yer