Use sort_values
to sort the df by a specific column’s values:
In [18]: df.sort_values('2') Out[18]: 0 1 2 4 85.6 January 1.0 3 95.5 February 2.0 7 104.8 March 3.0 0 354.7 April 4.0 8 283.5 May 5.0 6 238.7 June 6.0 5 152.0 July 7.0 1 55.4 August 8.0 11 212.7 September 9.0 10 249.6 October 10.0 9 278.8 November 11.0 2 176.5 December 12.0
If you want to sort by two columns, pass a list of column labels to sort_values
with the column labels ordered according to sort priority. If you use df.sort_values(['2', '0'])
, the result would be sorted by column 2
then column 0
. Granted, this does not really make sense for this example because each value in df['2']
is unique.
Related Posts:
- Find the unique values in a column and then sort them
- Renaming column names in Pandas
- How to reset index in a pandas dataframe? [duplicate]
- Delete a column from a Pandas DataFrame
- How to deal with SettingWithCopyWarning in Pandas
- How to deal with SettingWithCopyWarning in Pandas
- Constructing pandas DataFrame from values in variables gives “ValueError: If using all scalar values, you must pass an index”
- How to iterate over rows in a DataFrame in Pandas
- How to iterate over rows in a DataFrame in Pandas
- Writing a pandas DataFrame to CSV file
- Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- Writing a pandas DataFrame to CSV file
- Adding new column to existing DataFrame in Python pandas
- How to change the order of DataFrame columns?
- How to change the order of DataFrame columns?
- Pandas DataFrame Groupby two columns and get counts
- How can I use the apply() function for a single column?
- How to show all columns’ names on a large pandas dataframe?
- How to groupby based on two columns in pandas?
- How to deal with SettingWithCopyWarning in Pandas
- Merging dataframes on index with pandas
- Create a Pandas Dataframe by appending one row at a time
- How to replace NaN values by Zeroes in a column of a Pandas Dataframe?
- ValueError: Length of values does not match length of index | Pandas DataFrame.unique()
- Convert Python dict into a dataframe
- Creating an empty Pandas DataFrame, then filling it?
- How do I select rows from a DataFrame based on column values?
- How do I select rows from a DataFrame based on column values?
- Pandas group-by and sum
- How do I get the row count of a Pandas DataFrame?
- Python pandas groupby aggregate on multiple columns, then pivot
- Convert pandas dataframe to NumPy array
- DataFrame constructor not properly called
- Convert pandas Series to DataFrame
- How to iterate over rows in a DataFrame in Pandas
- Pandas group-by and sum
- How do I get the row count of a Pandas DataFrame?
- ValueError: Length of values does not match length of index | Pandas DataFrame.unique()
- ‘DataFrame’ object has no attribute ‘sort’
- ‘DataFrame’ object has no attribute ‘sort’
- Rename Pandas DataFrame Index
- pandas: filter rows of DataFrame with operator chaining
- ‘DataFrame’ object has no attribute ‘sort’
- Pandas, merging two dataframes on multiple columns, and multiplying result
- Convert DataFrame column type from string to datetime, dd/mm/yyyy format
- Get a list from Pandas DataFrame column headers
- What is dtype(‘O’), in pandas?
- How to read a .xlsx file using the pandas Library in iPython?
- Get total of Pandas column
- What is dtype(‘O’), in pandas?
- How to check whether a pandas DataFrame is empty?
- Change column type in pandas
- ValueError: ‘object too deep for desired array’
- Shuffle DataFrame rows
- What does axis in pandas mean?
- How to take column-slices of dataframe in pandas
- Combine two columns of text in pandas dataframe
- Python: pandas merge multiple dataframes
- How to count the NaN values in a column in pandas DataFrame
- Pandas – DataFrame object is not callable
- Convert a Pandas DataFrame to a dictionary
- Convert pandas data frame to series
- Create a Pandas Dataframe by appending one row at a time
- Normalize columns of pandas data frame
- Normalize columns of pandas data frame
- Selecting/excluding sets of columns in pandas
- How to filter Pandas dataframe using ‘in’ and ‘not in’ like in SQL
- How to apply a function to two columns of Pandas dataframe
- Pandas DataFrame: replace all values in a column, based on condition
- OSError: Initializing from file failed on csv in Pandas
- Data type conversion error: ValueError: Cannot convert non-finite values (NA or inf) to integer
- Pandas – How to flatten a hierarchical index in columns
- Insert a row to pandas dataframe
- Subtract two columns in dataframe
- How to check if a column exists in Pandas
- Pandas error “Can only use .str accessor with string values”
- How to get a value from a cell of a dataframe?
- Pandas split DataFrame by column value
- Groupby value counts on the dataframe pandas
- Rename specific column(s) in pandas
- Pandas index column title or name
- Coalesce values from 2 columns into a single column in a pandas dataframe
- How to add pandas data to an existing csv file?
- pandas groupby sort within groups
- if else function in pandas dataframe
- Read data (.dat file) with Pandas
- Move column by name to front of table in pandas
- How to convert index of a pandas dataframe into a column
- pandas comparison raises TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
- Pandas dataframe groupby plot
- Got continuous is not supported error in RandomForestRegressor
- Logical operators for Boolean indexing in Pandas
- vectorize conditional assignment in pandas dataframe
- Convert list of dictionaries to a pandas DataFrame
- Compare two columns using pandas
- alueError: ordinal must be >= 1
- How to customize a scatter matrix to see all titles?
- Normalize data in pandas
- pandas: multiple conditions while indexing data frame – unexpected behavior