Method to sort values in row in pandas Series?
<p>Consider the following <code>pandas.Series</code> object:</p>

<pre><code>import pandas as pd

s = pd.Series(["hello there you would like to sort me", "sorted i would like to be", "the yankees played the red sox", "apple apple banana fruit orange cucumber"])
</code></pre>

<p>I would like to sort the values <strong>inside</strong> each row, similar to the following approach:</p>

<pre><code>for row in s.index:
    split_words = s.loc[row].split()
    split_words.sort()
    s.loc[row] = " ".join(split_words)
</code></pre>

<p>I have a huge dataset, however, so vectorization is important, here. How can I use pandas <code>str</code> attribute to accomplish the same, but much quicker?</p>

<p>use the string accessor <code>str</code> and <code>split</code>.  Then apply <code>sorted</code> and <code>join</code>.</p>

<pre><code>s.str.split().apply(sorted).str.join(' ')

0       hello like me sort there to would you
1                   be i like sorted to would
2              played red sox the the yankees
3    apple apple banana cucumber fruit orange
dtype: object
</code></pre>

python pandas vector