Reputation: 507
I'm trying to calculate the mean of a column which contains a lists/series but get an error while doing so. The example dataframe as follows:
import pandas as pd
df = pd.DataFrame({'a': [[1,2,3]]})
df ['a'].mean()
The error as follows:
Could not convert [1, 2, 3] to numeric.
Not sure why this happens and how to fix it. Can someone please help? thanks
Upvotes: 0
Views: 335
Reputation: 323376
Since your cell value type is list
we need apply
df.a.apply(np.mean)
0 2.0
Name: a, dtype: float64
Upvotes: 3