0
$\begingroup$

I get the above mentioned error in this problem. Can anyone please help me correct it?

Example data frame: column ID with 3 numbers and column count with 3 numbers.

If key='count', the sum of the values in the count value will be obtained. If key='ID', the sum of the values in the ID column will be summed.

Current code:

def sum_column(X,key='count'):
   S = X[key].sum()
   return S
$\endgroup$
1
$\begingroup$

As far as I can understand from your code, your dictionary X does not contain values for the key count. You can set a value for count by invoking a line similar to X['count']=1. Now you will need to find out why this is the case (maybe a typo?). If you require more understanding of the problem, you might want to check out this page about KeyErrors.

Nevertheless, these types of questions are not solely related to Data Science, thus you may want to ask on a platform with a larger user base like Stack Overflow. This is also stated in the help center.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.