Questions provided below and my new column is returning null values when trying to find number of days. What am I missing? I’m trying to filter for the column ‘event_name’ where the subscription status is found and then subtract the two dates from the same table to create number of days column.
Create a new column with the number of days it takes users to start a subscription from the moment they register in the app
Then answer the following questions:
a. What is the average number of days it takes users to start a subscription from the users registered in January 2022?
b. From the total users how many started a subscription within their first 3 days (included 3rd day)?
Here’s my code snippet:
from datetime import datetime
import pandas as pd
df_events[‘created_at’] = df_events[‘created_at’].apply(lambda x: pd.to_datetime(str(x)))
df_trial_start = df_events[df_events.event_name == ‘SUBSCRIPTION_TRIAL_STARTED’]
df_start = df_events[df_events.event_name == ‘SUBSCRIPTION_STARTED’]
df_events[‘num_of_days’] = df_start[‘created_at’] - df_trial_start[‘created_at’]
print(df_events.head())