Jun-15-2018, 05:13 AM
(This post was last modified: Jun-15-2018, 05:13 AM by tryingtolearnpython.)
Hi everyone,
I'm very new to Python so my questions may be very basic for most of you.
I am not sure I understand the below function. The part I am having trouble understanding is:
I'm very new to Python so my questions may be very basic for most of you.
I am not sure I understand the below function. The part I am having trouble understanding is:
reactions = nacho_table.column('Reactions')
number_wow_reactions = np.count_nonzero(reactions == 'Wow!')
number_meh_reactions = np.count_nonzero(reactions == 'Meh.')How does Python know nacho_table is a table and not an array?def both_or_neither(nacho_table):
reactions = nacho_table.column('Reactions')
number_wow_reactions = np.count_nonzero(reactions == 'Wow!')
number_meh_reactions = np.count_nonzero(reactions == 'Meh.')
if number_wow_reactions > number_meh_reactions:
return 'Wow!'
elif number_wow_reactions < number_meh_reactions:
return 'Meh.'
else:
return 'Okay!'
# next condition should return 'Meh.'
...
# next condition should return 'Okay!'
...
many_nachos = Table().with_column('Nachos', np.random.choice(nachos, 250))
many_nachos = many_nachos.with_column('Reactions', many_nachos.apply(nacho_reaction, 'Nachos'))
result = both_or_neither(many_nachos)
result
