cancel
Showing results for 
Search instead for 
Did you mean: 

PyKX Project - Netflix - Exercise 8

MSSHAIKH11
New Contributor II

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"           ""   
'))

 

1 REPLY 1

gyorokpeter-kx
Contributor
Contributor

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