I used a slightly different approach from the dq solution; My question is whether my approach is correct or it only works in some situations and not in others.
I hope to learn from users if my understandings of the principles is correct.
rooms_above_ground = rooms_above_ground.replace('10 or more',10)
rooms_above_ground = rooms_above_ground.astype('int64')
rooms_above_ground = rooms_above_ground.sort_values()
if (len(lst) % 2) == 0:
return (lst[len(lst)//2-1] + lst[len(lst)//2])/2
mylst = rooms_above_ground.sort_values().tolist()
What I expected to happen:
What actually happened:
<!--Enter other relevant details below: -->
I used the function to first identify the indices, similar to the dq approach, but only with scalar quantities rather than using pandas ) iloc etc.).
I used floor division to get the numbers of the indices.
Is it possible that in some situations the number for indices may be off?
Hi @saleemdar.dr, I don’t understand what your question is but your code actually worked when I tried it, you didn’t follow the last instruction in the exercise which says you should assign it to a variable named median.
2930 you got was as a result of this code, inside your function you told it to print the length of the lst that’s why you got it but your median is ver correct.
If the results for both cases are similar to the results from other libraries, you function should be fine. If you’re up for it and if the library is open-sourced, you can also directly read the source code for the median function whether it’s in pandas or something else and compare the code with your function.
I believe that would satisfy you the most because those libraries are used by many people and should be reasonably correct i.e. if your implementation is similar to other popular libraries then your implementation is most likely correct.