[Tutor] Please help me on Python Code
Mats Wichmann
mats at wichmann.us
Wed Oct 16 19:12:35 EDT 2019
On 10/16/19 3:20 PM, André Pinto wrote:
> Dear.
>
>
>
> I have a question and I can't solve it.
>
> I need to average 40,000 items in a dataset and for each item I have 4
> different conditioners.
>
> I am writing the code as follows, but I am not achieving my goal which is to
> classify the item according to its conditional, it should get the number 1
> or the number zero and at the end the sum of them in a last column in the
> dataset.
>
> What is the best solution to this question? My code is:
sorry, we can't solve this for you, because there is too much missing
information. I'll give you the benefit of the doubt about the horribly
formatted code, which can't possibly run as it appears in this email,
and assume that the process of getting the code into the email, or your
email program itself, broke that part of it. You don't say in what way
you're not achieving the goal: is Python telling you your program has
errors and so isn't running it? Or are you not getting the results you
want?
here are two reactions:
>
>
>
> def media6(dataset):
>
> val6 = 10
>
> if 0 < dataset['43709'].isin([dataset]).all():
1/ dataset looks like it is an instance of a class, but we know nothing
all about that class, so .isin and .all might or might not be doing
anything useful for you.
[lots clipped]
> dataset[‘MEDIA’] = (media6 + media5 + media4 + media3 + media2 + media1)
You define these six functions, but just listing them by name doesn't
call them, so the functions are never being called. This will certainly
make your program do something different than you are expecting.
Here is a short interactive sesssion that shows that concept in action:
>>> def funcA():
... return 10
...
>>> def funcB():
... return 20
...
>>>
>>> x = (funcA + funcB)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'function' and 'function'
>>>
>>> x = funcA() + funcB()
>>> print(x)
30
>>>
More information about the Tutor
mailing list