Answers for "how to sort the dataframe base on one column in the dataframe in python"

23

sort dataframe by column

df.sort_values(by='col1', ascending=False)
Posted by: Guest on April-30-2020
3

dataframe, sort by columns

final_df = df.sort_values(by=['2'], ascending=False)
Posted by: Guest on September-22-2020
-1

dataframe sort by column

sorted = df.sort_values('column-to-sort-on', ascending=False)
#or
df.sort_values('name', inplace=True)
Posted by: Guest on May-13-2020
0

sort dataframe by column

df.sort_values(by='col1', ascending=False, na_position='first', inplace=True)
Posted by: Guest on July-02-2020
0

python df pandas sort by column

>>> df.sort_values("city08")
    city08  cylinders fuelType  ...  mpgData            trany  year
99       9          8  Premium  ...        N  Automatic 4-spd  1993
1        9         12  Regular  ...        N     Manual 5-spd  1985
80       9          8  Regular  ...        N  Automatic 3-spd  1985
47       9          8  Regular  ...        N  Automatic 3-spd  1985
3       10          8  Regular  ...        N  Automatic 3-spd  1985
..     ...        ...      ...  ...      ...              ...   ...
9       23          4  Regular  ...        Y  Automatic 4-spd  1993
8       23          4  Regular  ...        Y     Manual 5-spd  1993
7       23          4  Regular  ...        Y  Automatic 3-spd  1993
76      23          4  Regular  ...        Y     Manual 5-spd  1993
2       23          4  Regular  ...        Y     Manual 5-spd  1985
[100 rows x 10 columns]
Posted by: Guest on September-27-2021

Code answers related to "how to sort the dataframe base on one column in the dataframe in python"

Python Answers by Framework

Browse Popular Code Answers by Language