Business-metrics error not executing code

https://app.dataquest.io/m/468/business-metrics/5/analyzing-nps

I am getting an attribute error when i run the code locally in jupyter

so i tried to import matplotlib but stil get an error

import matplotlib.pyplot as plt

ax = nps.reset_index().plot(kind="line", x="yearmonth",y="nps",
                            figsize=(12,6), legend=False
                           )
ax.set_xticks(nps.index)
ax.set_xticklabels(nps.index, rotation=45)
ax.axes.get_xaxis().set_label_text("")

reset_index() is a DataFrame method, therefore nps must be a DataFrame so this method can be called. Is nps a DataFrame? Can you share the code you used to create it?

1 Like

Also, don’t forget, when you would like to run matplotlib in Jupyter Notebook:
use the inline magic: “%matplotlib inline”. This command works only there because Jupyter uses iPython instead of the regular python used throughout the missions.

1 Like

Hi otavios.s
I had it defined as a dataframe in the cell before

nps = df.pivot_table(index=“yearmonth”, columns=“category”, aggfunc=“size”)
nps[“total_responses”] = nps.sum(axis=“columns”)
nps[“nps”] = (nps[“Promoter”]-nps[“Detractor”])/nps[“total_responses”]
nps[“nps”] = (100*nps[“nps”]).astype(int)

now I rerun and read file in again from start and get text output

1 Like

Thanks David,

Indeed that was the problem, i added that for inline and it works now