Matching results but cannot pass the results check

Hi,

I wrote the code as below. The results seem to match yet they cannot pass the result check. Can anyone help me to have a check? Thanks!

My Code:

df = pd.read_csv("nps.csv", parse_dates=["event_date"])
df['yearmonth'] = df['event_date'].dt.strftime("%Y%m")

df['categorize'] = df['score'].apply(categorize)

nps = df.pivot_table(columns="categorize", index="yearmonth", aggfunc="size")
nps['total_responses'] = nps.sum(axis=1)
nps['nps'] = ((nps['Promoter'] - nps['Detractor']) / nps['total_responses'] * 100).astype(int)

Hi! @jiahuiw.au
Welcome to the community!
Can you please share the link to the notebook or project?

1 Like

Hi, thanks for replying! The link is https://app.dataquest.io/m/468/business-metrics/4/net-promoter-score

Here strftime will return string so you have to convert it into int

df['yearmonth'] = df['event_date'].dt.strftime("%Y%m").astype('int')

Second,

Here you suppose to give column name category instead categorize

image
So it would be

df['category'] = df['score'].apply(categorize)

nps = df.pivot_table(columns="category", index="yearmonth", aggfunc="size")
1 Like

Ahh I see, thanks a lot for your help! :slightly_smiling_face:

Glad it helps. Please consider mark reply as solution to close question or give like. :slightly_smiling_face:

1 Like