Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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 :: discord.py add reaction to message 
Python :: get working directory python 
Python :: convert grayscale to rgb python 
Python :: generate a list of random non repeated numbers python 
Python :: logging python utf-8 
Python :: To check pip version 
Python :: confusion matrix seaborn 
Python :: select items from dataframe where value is null 
Python :: how to convert dataframe to list in python 
Python :: get current month py 
Python :: edge driver selenium python 
Python :: python csv write add new line 
Python :: remove multiple space python 
Python :: knowing the sum of null value is pandas dataframe 
Python :: insert picture into jupyter notebook 
Python :: api xml response to json python 
Python :: how to count max repeated count in list python 
Python :: django.db.backends.mysql install 
Python :: how to sort in pandas 
Python :: install gtts 
Python :: pyspark create empty dataframe 
Python :: how to get a list of all values in a column df 
Python :: python flask replit 
Python :: convert tuple to array python 
Python :: selenium current url 
Python :: how to manually click button godot 
Python :: matplotlib subplots title 
Python :: python roll a die 
Python :: python read dictionary from file 
Python :: write set to txt python 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =