Act fast, special offers end soon! Up to $294 is savings when you get Premium today.
Get offer codes

Creating 'Others' in piechart

Screen Link:
https://app.dataquest.io/m/310/guided-project%3A-finding-the-best-markets-to-advertise-in/5/spending-money-for-learning

My Code:

table_norm = ncs_good['CountryLive'].value_counts(normalize = True)

table_abs = ncs_good['CountryLive'].value_counts()
print(table_norm[:5])
print('\n')
print(table_abs[:5])
other_norm = table_norm[5:].sum()
table_other = pd.Series['Other', other_norm]
table_norm.append(table_other)
table_norm

What I expected to happen:

So the idea of the whole thing was to create a row in table_norm which would contain the sum of all the locations that are not part of the top 5 and assign then to “Others” so my pie chart would be easier to read. This is probably not one of the clever ways to go about this, but it was what I could think till now, if anyone has a better solution than this one or knows how to fix this bug, I would gladly hear it out.

What actually happened:

TypeErrorTraceback (most recent call last)
<ipython-input-17-554afa05234c> in <module>()
      1 other_norm = table_norm[5:].sum()
----> 2 table_other = pd.Series['Other', other_norm]
      3 table_norm.append(table_other)
      4 table_norm

TypeError: 'type' object is not subscriptable

It can be difficult to help out here since your code and variable names are different compared to mine.

But I would recommend checking out the documentation for pandas.Series() because your current use of pd.Series() does not match the syntax of it.

Based on that try to first compare what you are doing vs what you want to do.

Thanks, I will do it!

did it here: (and it worked)