Simple way to calculate median with MySQL

In MariaDB / MySQL: Steve Cohen points out, that after the first pass, @rownum will contain the total number of rows. This can be used to determine the median, so no second pass or join is needed. Also AVG(dd.val) and dd.row_number IN(…) is used to correctly produce a median when there are an even number of records. Reasoning: Finally, MariaDB 10.3.3+ … Read more

Help needed with Median If in Excel

Assuming your categories are in cells A1:A6 and the corresponding values are in B1:B6, you might try typing the formula =MEDIAN(IF($A$1:$A$6=”Airline”,$B$1:$B$6,””)) in another cell and then pressing CTRL+SHIFT+ENTER. Using CTRL+SHIFT+ENTER tells Excel to treat the formula as an “array formula”. In this example, that means that the IF statement returns an array of 6 values (one of each of the cells in … Read more

Finding median of list in Python

How do you find the median of a list in Python? The list can be of any size and the numbers are not guaranteed to be in any particular order. If the list contains an even number of elements, the function should return the average of the middle two. Here are some examples (sorted for … Read more