Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 output confusion in sort_values of Pandas
#1
Given below is small program in python:
import pandas as pd
ontutD = {'Tutor': ['Tahira','Gagan','Anusha','Jacob','venkat',
'Tahira','Gagan','Anusha','Jacob','venkat',
'Tahira','Gagan','Anusha','Jacob','venkat',
'Tahira','Gagan','Anusha','Jacob','venkat'],
'Classes' : [28,36,41,32,40,36,40,36,40,46,24,30,44,40,32,36,32,36,42,38],
'Quarter' : [1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4],
'Country' : [ 'USA','UK','Japan','USA','Brazil','USA','USA','Japan',
'Brazil','USA','Brazil','USA','UK','Brazil','USA','Japan',
'Japan','Brazil','UK','USA']
}
df1 = pd.DataFrame(ontutD)
ks = df1.sort_values('Country')
print (ks)

Python 3.7.3 Output :
Output:
Tutor Classes Quarter Country 17 Anusha 36 4 Brazil 4 venkat 40 1 Brazil 8 Jacob 40 2 Brazil 10 Tahira 24 3 Brazil 13 Jacob 40 3 Brazil 2 Anusha 41 1 Japan 16 Gagan 32 4 Japan 15 Tahira 36 4 Japan 7 Anusha 36 2 Japan 1 Gagan 36 1 UK 18 Jacob 42 4 UK 12 Anusha 44 3 UK 0 Tahira 28 1 USA 14 venkat 32 3 USA 9 venkat 46 2 USA 6 Gagan 40 2 USA 5 Tahira 36 2 USA 3 Jacob 32 1 USA 11 Gagan 30 3 USA 19 venkat 38 4 USA
My confusion in index number:17, it will be come at 5th position ? please correct me
Output:
Tutor Classes Quarter Country 4 venkat 40 1 Brazil 8 Jacob 40 2 Brazil 10 Tahira 24 3 Brazil 13 Jacob 40 3 Brazil 17 Anusha 36 4 Brazil 2 Anusha 41 1 Japan 16 Gagan 32 4 Japan 15 Tahira 36 4 Japan 7 Anusha 36 2 Japan 1 Gagan 36 1 UK 18 Jacob 42 4 UK 12 Anusha 44 3 UK 0 Tahira 28 1 USA 14 venkat 32 3 USA 9 venkat 46 2 USA 6 Gagan 40 2 USA 5 Tahira 36 2 USA 3 Jacob 32 1 USA 11 Gagan 30 3 USA 19 venkat 38 4 USA
Quote
#2
you need to specify type of sorting algorithm to be mergesort
ks = df1.sort_values('Country', kind='mergesort')
default is 'quicksort' which is not stable
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Confusion with sublcassing a threading class, and inheritance bigmit37 2 151 Apr-08-2019, 09:28 AM
Last Post: DeaD_EyE
  readshapefile function in basemap - confusion regarding arguments sendiptangshu 1 164 Mar-09-2019, 09:29 AM
Last Post: Larz60+
  Sockets confusion! MuntyScruntfundle 1 288 Oct-16-2018, 07:18 PM
Last Post: Larz60+
  Python and bash command confusion MuntyScruntfundle 0 360 Oct-11-2018, 04:52 PM
Last Post: MuntyScruntfundle
  Unexpected output when searching for a string from os.popen output FujiJean 3 500 Oct-02-2018, 11:39 AM
Last Post: volcano63
  Confusion about Hashlib Vysero 2 441 Jun-25-2018, 04:05 PM
Last Post: DeaD_EyE
  Object madness - JSON Notation confusion execsys 4 741 May-03-2018, 08:56 AM
Last Post: buran
  confusion on print function volcano 3 827 Mar-11-2018, 10:41 AM
Last Post: snippsat
  Function Attribute / Global Variable Confusion digitalmatic7 1 915 Feb-13-2018, 09:54 AM
Last Post: DeaD_EyE
  python indentation confusion hello_its_me 5 1,183 Sep-02-2017, 12:04 PM
Last Post: hello_its_me

Forum Jump:


Users browsing this thread: 1 Guest(s)