Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to sort in pandas

// Single sort 
>>> df.sort_values(by=['col1'],ascending=False)
// ascending => [False(reverse order) & True(default)]
// Multiple Sort
>>> df.sort_values(by=['col1','col2'],ascending=[True,False])
// with apply() 
>>> df[['col1','col2']].apply(sorted,axis=1)
// axis = [1 & 0], 1 = 'columns', 0 = 'index'
Comment

pandas series sort

s.sort_values(ascending=True)
1     1.0
2     3.0
4     5.0
3    10.0
0     NaN
dtype: float64
Comment

sort a series pandas

>>> s.sort_values(ascending=False, inplace=True)
>>> s
3    10.0
4     5.0
2     3.0
1     1.0
0     NaN
dtype: float64
Comment

sort a series pandas

>>> s.sort_values(ascending=True)
1     1.0
2     3.0
4     5.0
3    10.0
0     NaN
dtype: float64
Comment

PREVIOUS NEXT
Code Example
Python :: np to tuple 
Python :: how to delete json object using python? 
Python :: remove character from string by index in python 
Python :: title() function in python 
Python :: To View the entire Row and Column in a Dataframe 
Python :: python google chrome 
Python :: difference between generator and iterator in python 
Python :: how to create frequency table in python 
Python :: change color of butto in thkinter 
Python :: try open file 
Python :: python remove string from string 
Python :: python check if number is in range 
Python :: python set and dictionary comprehensions 
Python :: how to get username with userid discord.py 
Python :: Python Requests Library Get Method 
Python :: python fillna with mode 
Python :: registration of path in urls.py for your apps for views 
Python :: as type in pandas 
Python :: python pyqt5 sleep 
Python :: python check if int 
Python :: django cookies 
Python :: sha512 python 
Python :: discord.py fetch channel 
Python :: how to calculate sum of a list in python 
Python :: python http.server 
Python :: print in binary python 
Python :: python read lines 
Python :: import excel python 
Python :: onehotencoder pyspark 
Python :: csv writer python 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =