468-4 Results match but code incorrect for yearmonth

Screen Link:
https://app.dataquest.io/m/468/business-metrics/4/net-promoter-score

My Code:

import pandas as pd

df = pd.read_csv("nps.csv", parse_dates=["event_date"])

df['yearmonth'] = df['event_date'].dt.strftime('%Y%m')
df['category'] = df['score'].apply(categorize)
nps = df.pivot_table(index = 'yearmonth', columns = 'category', aggfunc = 'size')
nps['total_responses'] = nps.sum(axis = 1)
nps['nps'] = (nps['Promoter']-nps['Detractor'])/nps['total_responses']
nps['nps'] = (nps['nps']*100).astype(int)

What I expected to happen:
Create yearmonth column in format yyyymm using dt.strftime(’%Y%m’)

What actually happened:
column successfully created in correct format, and final results match the ‘expected’ results for both df and nps, but the autograder says both are incorrect.

Please let me know if this is a problem with the autograder or why my code returns as incorrect here - perhaps I am missing something conceptually or in the middle of the dataframes there’s something that’s off that I can’t view.

Thank you!

5 Likes

Hey, Jake.

Your solution looks good, it’s missing a detail given in the instructions:

  1. Create a numeric column in df called yearmonth that stores the year and the month of each row in the yyyymm format.
4 Likes

Also worth noting that if you convert to int32 the answer will be graded incorrectly. So whenever Dataquest asks numeric in this mission it is int datatype.