Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with 1 . 5 . I am getting errors: - - - - - - - - - - - - -

I need help with 1.5. I am getting errors: ---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[101], line 3
1 #TODO Add Code to find the top donors supporting each committee.
2 groupcol =['top20donors', 'topcommittees']
---->3 campaignsbydonor = df.groupby(groupcol)['contribution_receipt_amount'].sum().reset_index()
5 campaignsbydonors =[]
7 # when you are done this should display the first five rows from your new dataframe
File ~/anaconda3/lib/python3.11/site-packages/pandas/core/frame.py:8402, in DataFrame.groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, observed, dropna)
8399 raise TypeError("You have to supply one of 'by' and 'level'")
8400 axis = self._get_axis_number(axis)
->8402 return DataFrameGroupBy(
8403 obj=self,
8404 keys=by,
8405 axis=axis,
8406 level=level,
8407 as_index=as_index,
8408 sort=sort,
8409 group_keys=group_keys,
8410 squeeze=squeeze,
8411 observed=observed,
8412 dropna=dropna,
8413)
File ~/anaconda3/lib/python3.11/site-packages/pandas/core/groupby/groupby.py:965, in GroupBy.__init__(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, observed, mutated, dropna)
962 if grouper is None:
963 from pandas.core.groupby.grouper import get_grouper
-->965 grouper, exclusions, obj = get_grouper(
966 obj,
967 keys,
968 axis=axis,
969 level=level,
970 sort=sort,
971 observed=observed,
972 mutated=self.mutated,
973 dropna=self.dropna,
974)
976 self.obj = obj
977 self.axis = obj._get_axis_number(axis)
File ~/anaconda3/lib/python3.11/site-packages/pandas/core/groupby/grouper.py:888, in get_grouper(obj, key, axis, level, sort, observed, mutated, validate, dropna)
886 in_axis, level, gpr = False, gpr, None
887 else:
-->888 raise KeyError(gpr)
889 elif isinstance(gpr, Grouper) and gpr.key is not None:
890 # Add key to exclusions
891 exclusions.add(gpr.key)
KeyError: 'top20donors'
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

2. What efforts are countries making to reverse the brain drain?

Answered: 1 week ago