Python - problema con ejercicio de python

 
Vista:
Imágen de perfil de zahir

problema con ejercicio de python

Publicado por zahir (5 intervenciones) el 30/12/2021 02:57:07
from numpy import array
import pandas as pd

def calcular_estadisticas(descargas: pd.DataFrame) -> pd.DataFrame:
filtrado = descargas[descargas["PAGO"] > 0]
dic = {"CANTIDAD": 0, "PROMEDIO": 0, "MAXIMO": 0, "MINIMO": 0,
"ESTRELLAS": 0, "DESV. ESTRELLAS": 0, "COMENTARIOS": 0}
dic["CANTIDAD"] = filtrado["MODELO"].value_counts()
agrupado = filtrado.groupby("MODELO")
index = []
promedio = []
maximo = []
minimo = []
estrellas = []
desviacion = []
coment = []
for name, group in agrupado:
index.append(name)
grupo = agrupado.get_group(name)
promedio.append(grupo["PAGO"].mean())
maximo.append(grupo["PAGO"].max())
minimo.append(grupo["PAGO"].min())
estrellas.append(grupo["ESTRELLAS"].mean())
desviacion.append(grupo["ESTRELLAS"].std())
coment.append(len(grupo[grupo["COMENTARIO"]]))
dic["PROMEDIO"] = pd.Series(promedio, index=index)
dic["MAXIMO"] = pd.Series(maximo, index=index)
dic["MINIMO"] = pd.Series(minimo, index=index)
dic["ESTRELLAS"] = pd.Series(estrellas, index=index)
dic["DESV. ESTRELLAS"] = pd.Series(desviacion, index=index)
dic["COMENTARIOS"] = pd.Series(coment, index=index)
df1 = pd.DataFrame(dic)
df1["PROMEDIO"] = df1["PROMEDIO"].round(2)
df1["DESV. ESTRELLAS"] = df1["DESV. ESTRELLAS"].fillna(0).round(2)
df1 = df1.sort_index()
return df1



parte-1
parte2
parte-3
py2
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder