Python pandas dataframe sort_values does not work
<p>I have the following pandas data frame which I want to sort by 'test_type'</p>

<pre><code>  test_type         tps          mtt        mem        cpu       90th
0  sso_1000  205.263559  4139.031090  24.175933  34.817701  4897.4766
1  sso_1500  201.127133  5740.741266  24.599400  34.634209  6864.9820
2  sso_2000  203.204082  6610.437558  24.466267  34.831947  8005.9054
3   sso_500  189.566836  2431.867002  23.559557  35.787484  2869.7670
</code></pre>

<p>My code to load the dataframe and sort it is, the first print line prints the data frame above.</p>

<pre><code>        df = pd.read_csv(file) #reads from a csv file
        print df
        df = df.sort_values(by=['test_type'], ascending=True)
        print '\nAfter sort...'
        print df
</code></pre>

<p>After doing the sort and printing the dataframe content, the data frame still looks like below.</p>

<p>Program output:</p>

<pre><code>After sort...
  test_type         tps          mtt        mem        cpu       90th
0  sso_1000  205.263559  4139.031090  24.175933  34.817701  4897.4766
1  sso_1500  201.127133  5740.741266  24.599400  34.634209  6864.9820
2  sso_2000  203.204082  6610.437558  24.466267  34.831947  8005.9054
3   sso_500  189.566836  2431.867002  23.559557  35.787484  2869.7670
</code></pre>

<p>I expect row 3 (test type: sso_500 row) to be on top after sorting. Can someone help me figure why it's not working as it should?</p>

<p>Alternatively, you could also extract the numbers from <code>test_type</code> and sort them. Followed by reindexing <code>DF</code> according to those indices.</p>

<pre><code>df.reindex(df['test_type'].str.extract('(\d+)', expand=False)    \
                          .astype(int).sort_values().index).reset_index(drop=True)
</code></pre>

<p><a href="http://i.stack.imgur.com/7Xu95.png" rel="nofollow"><img src="http://i.stack.imgur.com/7Xu95.png" alt="Image"></a></p>

python pandas