pandas - Sorting data on column -


how sort dataframe based on first column in multiindexed column?

mypivot                  url status           200  301  302  304  404 ip 900.43.91.8        1    1    1  nan    1 07.167.103.22    18  nan  nan  nan    1 17.211.102.92    18  nan  nan  nan    2 17.216.172.5     21  nan  nan  nan    1 18.151.211.10    19  nan  nan  nan    2 25.18.235.210    12  nan  nan  nan  nan 34.139.155.135   733    2  nan  301   53 11.216.235.175    8  nan  nan  nan  nan 7.228.106.211    18  nan  nan  nan    1 2.104.61.135     18  nan  nan  nan    1 9.58.151.168      2  nan  nan  nan  nan 6.249.67.53     nan  nan    1  nan    2 6.249.67.66       1    2  nan  nan  nan 6.249.67.79       1  nan    1  nan    1 9.37.224.70        1  nan  nan  nan  nan 6.110.226.29      1    1    1  nan  nan 

the ip address 34.139.155.135 should @ top because has maximum number 200 status.

i have tried following 3 statements none of them sorting on 200 status column.

mypivot.sort() mypivot.sort(ascending=false) mypivot.sort(ascending=false , axis=1) 

the data types are:

<class 'pandas.core.frame.dataframe'> index: 16 entries, 900.43.91.8 6.110.226.29 data columns (total 5 columns): (url, 200)    15 non-null float64 (url, 301)    4 non-null float64 (url, 302)    4 non-null float64 (url, 304)    1 non-null float64 (url, 404)    10 non-null float64 dtypes: float64(5) 

and here columns levels.

in [85]: mypivot.columns out[85]: multiindex(levels=[[u'url'], [200, 301, 302, 304, 404]],            labels=[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4]],            names=[none, u'status']) 

mypivot.sort([('url', 200)], ascending=false) 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -