Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

df sort values

>>> df.sort_values(by=['col1'], ascending = False)
    col1 col2 col3
0   A    2    0
1   A    1    1
2   B    9    9
5   C    4    3
4   D    7    2
3   NaN  8    4
Comment

df .sort_values

df.sort_values(by=['col1'], ascending = True)
Comment

python sort_values

df.sort_values(by='col4', key=lambda col: col.str.lower())
   col1  col2  col3 col4
0    A     2     0    a
1    A     1     1    B
2    B     9     9    c
3  NaN     8     4    D
4    D     7     2    e
5    C     4     3    F
Comment

python sort_values

df = pd.DataFrame({
...    "time": ['0hr', '128hr', '72hr', '48hr', '96hr'],
...    "value": [10, 20, 30, 40, 50]
... })
>>> df
    time  value
0    0hr     10
1  128hr     20
2   72hr     30
3   48hr     40
4   96hr     50
>>> from natsort import index_natsorted
>>> df.sort_values(
...    by="time",
...    key=lambda x: np.argsort(index_natsorted(df["time"]))
... )
    time  value
0    0hr     10
3   48hr     40
2   72hr     30
4   96hr     50
1  128hr     20
Comment

python sort_values

df.sort_values(by=['col1'])
  col1  col2  col3 col4
0    A     2     0    a
1    A     1     1    B
2    B     9     9    c
5    C     4     3    F
4    D     7     2    e
3  NaN     8     4    D
Comment

PREVIOUS NEXT
Code Example
Python :: ardent 
Python :: how to use global variable in python 
Python :: python random list of integers without repetition 
Python :: create a blank image cv2 
Python :: python web parse 
Python :: publisher python ros 
Python :: how to plot confusion matrix 
Python :: % operatior in python print 
Python :: python parallel processing for loop 
Python :: push to pypi 
Python :: progressbar time in python 
Python :: how to get today weekday in python 
Python :: python pathlib create directory if not exists 
Python :: python sort columns of pandas dataframe 
Python :: combine dataframes with two matching columns 
Python :: know datatype of pandas 
Python :: Python remove punctuation from a string 
Python :: check remote port is open or not using python 
Python :: count down for loop python 
Python :: python functions 
Python :: how to read numbers in csv files python 
Python :: change tkinter app icon 
Python :: how to create 3 dimensional array in numpy 
Python :: run exe from python 
Python :: python lists as dataframe rows 
Python :: tensorflow keras load model 
Python :: pandas categorical to numeric 
Python :: Kill python background process 
Python :: python replace two spaces with one 
Python :: check python version windows 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =