Timeout error running your code

I currently have this issue for churn rate in business metrics mission. I have been able to successfully pass the answer checker using your suggestion.
I felt I should still inform you about it. Thanks

1 Like

Hi @glonimi0,

Sorry about that! I am unable to reproduce this issue on my end. Can you please send me the code you have used? Or can you try running a modified version of the solution code to bypass the mark screen complete workaround?


import datetime as dt

# create a function that takes as input an integer representing a month in the format yyyymm 
# it should return the number of rows in subs 
# it should satisfy the following criteria:
# start_date occurred before the first day of then given month
# end_date is later than the last day of the previous month
def count_subs(yearmonth):
    year = yearmonth//100
    month = yearmonth-year*100
    date = dt.datetime(year, month, 1)
    return ((subs['start_date'] < date) & (date <= subs['end_date'])).sum()
#create a column in churn called total_customers that is the result of applying the functio count_subs to churn['yearmonth']
churn['total_customers'] = churn['yearmonth'].apply(count_subs)

#calculate the churn_rate for each month and save in column churn_rate
churn['churn_rate'] = churn['total_churned']/churn['total_customers']

#set the yearmonth as a string type
churn['yearmonth'] = churn['yearmonth'].astype(int)

arange = __import__("numpy").arange
Ellipse = __import__("matplotlib").patches.Ellipse
ax = churn.plot(x="yearmonth", y="churn_rate", figsize=(12,6), rot=45, marker=".")
start, end = ax.get_xlim()
ax.set_xticks(arange(2, end, 3))
circle = Ellipse((35, churn.loc[churn.yearmonth == "201312", "churn_rate"].iloc[0]),
                 5, 0.065, color='sandybrown', fill=False

I have run the solution code already

Weird! I was able to reproduce the issue with the above code, however, when I changed:

churn['yearmonth'] = churn['yearmonth'].astype(int)


churn['yearmonth'] = churn['yearmonth'].astype(str)

the code ran perfectly. In any case, I will get this issue logged. Thank you for bringing this up.


1 Like

I just checked, it was my mistake. The question said to convert to string type and not int type. Thank you

1 Like

Thank you for letting me know. I will delete the bug report.