Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function not working
#1
def most_murderous(year):
    # Assign most to a table of the most murderous states this year in ascending order.
    data_for_year = murder_rates('Year', are.equal_to(year))
    sorted_data = data_for_year.sort('Murder Rate', descending=True)
    top_5 = sorted_data.take(np.arange(0,5))
    top_5.barh('State', 'Murder Rate')
    return top_5.column('State')

most_murderous(1990) # California, Mississippi, ..., 
I get an error saying

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-46-7e6222b8c39b> in <module>()
      7     return top_5.column('State')
      8 
----> 9 most_murderous(1990) # California, Mississippi, ...,

<ipython-input-46-7e6222b8c39b> in most_murderous(x)
      1 def most_murderous(x):
      2     # Assign most to a table of the most murderous states this year in ascending order.
----> 3     data_for_year = murder_rates('Year', are.equal_to(x))
      4     sorted_data = data_for_year.sort('Murder Rate', descending=True)
      5     top_5 = sorted_data.take(np.arange(0,5))

TypeError: 'Table' object is not callable
What is wrong here?

It seems:

data_for_year = murder_rates('Year', are.equal_to(year))

is wrong but I can't figure out what is wrong with it.

nevermind. I see that I'm missing a .where
Reply
#2
Please re-post error traceback, complete and unaltered. You have eliminated some very important information.
Reply
#3
Hi Larz,

I saw where I was making a mistake. I needed murder_rates.where('Year, are.equal_to(year))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked kindly support with this dropna function not working gheevarpaulosejobs 2 665 Jul-24-2023, 03:41 PM
Last Post: deanhystad
Exclamation Function Not Working Alivegamer 7 1,865 Jul-19-2022, 01:03 PM
Last Post: deanhystad
  try function working on PC but not raspberry pi AnotherSam 1 1,531 Oct-11-2021, 04:51 AM
Last Post: bowlofred
  Input() function not working in VS Code darpInd 7 13,288 Feb-17-2020, 03:28 PM
Last Post: snippsat
  Unrelated new function causing existing working function to fail Nick_G 2 2,255 Jan-27-2020, 07:21 PM
Last Post: Nick_G
  User Defined function not working Raj_Kumar 4 3,001 Dec-17-2019, 12:44 PM
Last Post: buran
  Function not working eglaud 0 1,645 Oct-24-2019, 03:30 PM
Last Post: eglaud
  Invoking function in if else statement, not working! ibaad1406 13 5,607 May-30-2019, 09:05 PM
Last Post: ibaad1406
  function for SQLite query not working pythonNoob 1 2,795 May-16-2018, 05:21 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020