I have the **dataframe** called " **table** The "Class" column is a column in which the data are grouped into class intervals. In the column " **fi** "column contains the absolute frequencies of the observations. In the column " **Fi** "We have the accumulated frequencies. Applying `scipy.stats`

I try to get the grouped median

```
from scipy import stats
#Mediana de una muestra de observaciones
tabla = {'Rango' : ["0-5", "5-10", "10-15", "15-20", "20-25", "25-30"],
"LimExaInf" : [0, 5, 10, 15, 20, 25],
"LimExaSup" : [5, 10, 15, 20, 25, 30],
"fi": [6, 10, 3, 5, 9, 4],
"Fi": [6, 16, 19, 24, 33, 37]}
tabla = pd.DataFrame(tabla, dtype = np.float64)
print("\nMediana :", stats.median_grouped(tabla["fi"]))
```

The script returns the error mentioned in the title.

AttributeError: module 'scipy.stats' has no attribute 'median_grouped' Realizando el cálculo aplicando la fórmula

**Modal range** is the interval that has the highest absolute efficiency.
**Li** is the lower limit of the modal range.

If we apply the formula, for which I have developed the following script.

```
N = tabla["fi"].sum()
for i in range (0, tabla.shape[0]):
if tabla["Fi"][i] > N/2:
Li = tabla ["LimExaInf"][i]
Ls = tabla ["LimExaSup"][i]
ci = Ls - Li
M = Li + ( ((N/2) - tabla["Fi"][i-1])/ tabla["fi"][i])*ci
break
print ("\nMediana :", M)
```

the result is 14.17.

I would appreciate help in correctly applying the above function.

0 votes

I've been thinking about it and trying things out and I think that

`statistics.median_grouped(data, intervalo)`

is intended for data without counting. I have created a couple of tables with values that fit within your class and frequency intervals and I get 14 when I use an interval of 6 and in another table that I know the result also gives me a similar value. I still don't know if there is a rounding error or if I am missing something, but I think the intention of these functions is to use them directly with the raw data.