efficient way of computing a list with mean of values in another list

I need to compute a list with the mean values of another list. To be more precise, the input list have this form:

input_list =


And I need to compute a list with the mean of the values before and after the slash ("/"), like this result:

desired_output =

[1.5381616, 42.5074916]

I can obtain the desired_output correctly using this code:

desired_output = pd.Series(input_list)\
                .apply(lambda r: pd.Series(r.split('/')))\

However, I have a very large number of input lists and the proposed code is somewhat slow, so I need to find a more efficient way to do it.

Any suggestions?

>Solution :

Create a numpy array with dtype=float, then calculate mean along axis=0

np.array([s.split('/') for s in input_list], dtype=float).mean(0)

array([ 1.5381616, 42.5074916])

Leave a Reply