Flatten a Series in pandas, i.e. a series whose elements are lists
pandas, python, python-3.x, series
Solution
s.map(len).sum()
does the trick. `s.map(len)` applies `len()` to each element and returns a series of all the lengths, then you can just use `sum` on that series.
Problem
I have a series of the form: ``` s = Series([['a','a','b'],['b','b','c','d'],[],['a','b','e']]) ``` which looks like ``` 0 [a, a, b] 1 [b, b, c, d] 2 [] 3 [a, b, e] dtype: object ``` I would like to count how many elements I have in total. My naive tentatives like ``` s.values.hist() ``` or ``` s.values.flatten() ``` didn't work. What am I doing wrong?