KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums PyKX PyKX Project – Netflix – Exercise 8

  • PyKX Project – Netflix – Exercise 8

    Posted by msshaikh11 on December 4, 2023 at 12:00 am

    Hi, 

    I have a problem with the last exercise (ex8) of the PyKX project.

    The problem is to :

    Sort the table on the viewsMillion column, from highest to lowest.

    Save the result to a new q table called sortedViews in q memory space.

    Here is my attempted solutions: 

    sortedViews = views.sort_values(by=’viewsMillion’,ascending = False).reset_index(drop=True)

    sortedViews = kx.K(sortedViews)
    kx.q[‘sortedViews’] = sortedViews

    (I have even tried the table from ex7.  (viewTab) )

    other alternative solutions attempts:

    #sortedViews = kx.q.sql("select * from viewtab order by viewsMillion desc") # your code here – attempt 1
    #sortedViews = kx.q.qsql.select(sortedViews, columns = [‘0′,’title’,’category’,’language’,’viewsMillion’]) – attempt 2

    – When I run the test function it states I have incorrect number of records even though the previous exercises have passed and ex8 is just asking to sort the table. by views. 

    pykx.Table(pykx.q(' quizItem  success description                                         error --------------------------------------------------------------------------- exercise8 Pass    "sortedViews exists in q memory space"              ""    exercise8 Pass    "sortedViews should be a q table"                   ""    exercise8 Fail    "sortedViews should have correct number of records" ""    exercise8 Pass    "sortedViews should have correct columns"           ""    '))

     

    msshaikh11 replied 9 months, 3 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • gyorokpeter-kx

    Member
    December 5, 2023 at 12:00 am

    Although this is not spelled out exactly in the exercise, it is expecting you to use the output of exercise 7. So if you run the test for exercise 7 and it passes, then use viewtab in exercise 8, it should have the correct number of rows.

    What is your number of rows in viewtab before and after exercise 7, and what is the number of rows in sortedViews?

Log in to reply.