Answers for "df sort by"

12

sorting by column in pandas

# Python, Pandas
# Sorting dataframe df on the values of a column col1

# Return sorted array without modifying the original one
df.sort_values(by=["col1"]) 

# Sort the original array permanently
df.sort_values(by=["col1"], inplace = True)
Posted by: Guest on April-08-2020
25

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
Posted by: Guest on April-07-2020
2

sort by dataframe

DataFrame.sort_values(self, by, axis=0, ascending=True,
                      inplace=False, kind='quicksort',
                      na_position='last',
                      ignore_index=False)

# Example
df.sort_values(by=['ColToSortBy'])
Posted by: Guest on March-13-2020
3

sort df by column

df.rename(columns={1:'month'},inplace=True)
df['month'] = pd.Categorical(df['month'],categories=['December','November','October','September','August','July','June','May','April','March','February','January'],ordered=True)
df = df.sort_values('month',ascending=False)
Posted by: Guest on May-29-2020
0

pandas dataframe sort by column

df.sort_values(by=['col1])
Posted by: Guest on May-30-2021
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

Python Answers by Framework

Browse Popular Code Answers by Language