python - pandas: calculate mean of numpy array for each row in a column -


i have pandas dataframe, df , contains columns each row contains numpy array of varying size e.g.

   column  0  np.array([1,2,3]) 1  np.array([1,2,3,4]) 2  np.array([1,2]) 

i there built in pandas function return mean value of each array, i.e. row, entire column? :

df.a.mean() 

but operates on each row. help.

you can use df.<column>.map apply function each element in column:

df = pd.dataframe({'a':      [np.array([1, 2, 3]),       np.array([4, 5, 6, 7]),       np.array([7, 8])] })  df out[8]:                0     [1, 2, 3] 1  [4, 5, 6, 7] 2        [7, 8]  df['a'].map(lambda x: x.mean()) out[9]:  0    2.0 1    5.5 2    7.5 name: a, dtype: float64 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -