Is there an analog for reduce
for a pandas Series?
For example, the analog for map
is pd.Series.apply, but I can't find any analog for reduce
.
My application is, I have a pandas Series of lists:
>>> business["categories"].head()
0 ['Doctors', 'Health & Medical']
1 ['Nightlife']
2 ['Active Life', 'Mini Golf', 'Golf']
3 ['Shopping', 'Home Services', 'Internet Servic...
4 ['Bars', 'American (New)', 'Nightlife', 'Loung...
Name: categories, dtype: object
I'd like to merge the Series of lists together using reduce
, like so:
categories = reduce(lambda l1, l2: l1 + l2, categories)
but this takes a horrific time because merging two lists together is O(n)
time in Python. I'm hoping that pd.Series
has a vectorized way to perform this faster.