Skip to content
Advertisement

Can we get duplicated values and get the mean of the value from lists

Hello this is using python panda

JavaScript

From the above code what I get is

JavaScript

From this list I want to actually get the mean of the values inside the class list. For example for ABC I want to get (123+345+678)/3 and for JIK (456+789)/2.

I tried getting the mean of the values but I found out inside lists we cannot change values. I’m not sure if I got it wrong or does anyone know how to get the mean inside a list?

Advertisement

Answer

You can get the mean with a comprehension –

JavaScript

If you want to add these mean values back into the original dict –

JavaScript

Output

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement