Python Pandas DataFrame.sort_values() Syntax
Syntax: DataFrame.sort_values(by, axis=0, ascending=True, inplace=False, kind=’quicksort’, na_position=’last’)
Note: Every parameter has some default values except the ‘by’ parameter.
Parameters:
- by: Single/List of column names to sort Data Frame by.
- axis: 0 or ‘index’ for rows and 1 or ‘columns’ for Column.
- ascending: Boolean value which sorts Data frame in ascending order if True.
- inplace: Boolean value. Makes the changes in passed data frame itself if True.
- kind: String which can have three inputs(‘quicksort’, ‘mergesort’ or ‘heapsort’) of algorithm used to sort data frame.
- na_position: Takes two string input ‘last’ or ‘first’ to set position of Null values. Default is ‘last’.
Return Type:
Returns a sorted Data Frame with Same dimensions as of the function caller DataFrame.
For link to CSV file Used in Code, click here.
Python | Pandas Dataframe.sort_values() | Set-1
Python is a great language for data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages, making importing and analyzing data much easier. Pandas sort_values() function sorts a data frame in Ascending or Descending order of passed Column. It’s different than the sorted Python function since it cannot sort a data frame and a particular column cannot be selected.
Let’s discuss the Dataframe.sort_values() Single Parameter Sorting