Combining Data with Python

Screen Link:
https://app.dataquest.io/m/344/combining-data-with-pandas/9/challenge-combine-data-and-create-a-visualization

My Code:

happiness2017.rename(columns={'Happiness.Score': 'Happiness Score'}, inplace=True)
combined = pd.concat([happiness2015, happiness2016, happiness2017], axis=0)
pivot_table_combined = combined_grouped.pivot_table(index = 'Year', values = 'Happiness Score', aggfunc = np.max)
pivot_table_combined.plot(kind = 'barh', title = 'Mean Happiness Scores by Year', xlim = (0,10))


What I expected to happen:
I expected my code to not give the correct output as I am using np.max as an aggregating function rather than np.mean

What actually happened:

It is showing that my output is correct. I do not understand how that’s happening.

Running your code caused this:

NameErrorTraceback (most recent call last)
<ipython-input-1-dbc8eae44e21> in <module>()
      1 happiness2017.rename(columns={'Happiness.Score': 'Happiness Score'}, inplace=True)
      2 combined = pd.concat([happiness2015, happiness2016, happiness2017], axis=0)
----> 3 pivot_table_combined = combined_grouped.pivot_table(index = 'Year', values = 'Happiness Score', aggfunc = np.max)
      4 pivot_table_combined.plot(kind = 'barh', title = 'Mean Happiness Scores by Year', xlim = (0,10))

NameError: name 'combined_grouped' is not defined

The variable combined_grouped in the line 3 was not defined. You should be using the combined variable, which was defined in the line 2. I don’t how this code could be working.

When I fixed that, the code did not raise an error anymore, but the answer-checking mechanism did not approve it:

Your 1st plot doesn’t match what we expected.

1 Like

Yes, now I am having the output as expected. But still I think it might be a bug as my code was running before.
Thanks for the help!

1 Like