Skip to content
Advertisement

How to get statistics from an array Collection ? (min max, and average)

I have a text file that has a long 2D array as follows:

JavaScript

The first element of each has numbers between 1 to 7. I want to read information of second element for all and find the maximum and minimum amount for each group between 1 to 7 separately. For example output like this:

JavaScript

What is the most efficient way of getting min, max, and average values by grouping based on the first element of the array?

JavaScript

Advertisement

Answer

We can use pandas for this:

JavaScript

This gives us:

JavaScript
Advertisement