Here an example. df1 will hold sorted dataframe and df will be intact

import pandas as pd
from datetime import datetime as dt
df = pd.DataFrame(data=[22,22,3],
                  index=[dt(2016, 11, 10, 0), dt(2016, 11, 10, 13), dt(2016, 11, 13, 5)],
                  columns=['foo'])

df1 = df.sort_values(by='foo')
print(df, df1)

In the case below, df will hold sorted values

import pandas as pd
from datetime import datetime as dt

df = pd.DataFrame(data=[22,22,3],
                  index=[dt(2016, 11, 10, 0), dt(2016, 11, 10, 13), dt(2016, 11, 13, 5)],
                  columns=['foo'])

df.sort_values(by='foo', inplace=True)
print(df)
Answer from Alexey Smirnov on Stack Overflow
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.Series.sort_values.html
pandas.Series.sort_values — pandas 3.0.2 documentation
Series.sort_values(*, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False, key=None)[source]#
🌐
W3Schools
w3schools.com › python › pandas › ref_df_sort_values.asp
Pandas DataFrame sort_values() Method
import pandas as pd data = { "age": ... newdf = df.sort_values(by='age') Try it Yourself » · The sort_values() method sorts the DataFrame by the specified label. dataframe.sort_values(by, axis, ascending, inplace, kind, ...
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › python-pandas-dataframe-sort_values-set-1
Pandas Dataframe.sort_values() - GeeksforGeeks
November 29, 2024 - The sort_values() function in Pandas is a versatile tool for sorting DataFrames by specific columns, with multiple options for handling null values and choosing sorting algorithms.
🌐
Real Python
realpython.com › pandas-sort-python
pandas Sort: Your Guide to Sorting Data in Python – Real Python
June 13, 2023 - With inplace set to True, you modify the original DataFrame, so the sort methods return None. Sort your DataFrame by the values of the city08 column like the very first example, but with inplace set to True:
🌐
Medium
medium.com › @whyamit101 › understanding-pandas-sort-values-with-basic-examples-e8e0f974d2c7
Understanding pandas.sort_values() with Basic Examples | by why amit | Medium
February 26, 2025 - Now, when you print df, it’s already sorted—no need for a new variable. Quick Tip: Be careful with inplace=True because it changes your data permanently unless you’ve got a backup. ... Here’s where things get interesting. What if your data has missing values (NaN)? By default, pandas puts them at the bottom when sorting.
Find elsewhere
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.23 › generated › pandas.DataFrame.sort_values.html
pandas.DataFrame.sort_values — pandas 0.23.1 documentation
Extending Pandas · Release Notes · Enter search terms or a module, class or function name. DataFrame.sort_values(by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')[source]¶ · Sort by the values along either axis · Examples · >>> df = pd.DataFrame({ ...
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.sort_values.html
pandas.Series.sort_values — pandas 3.0.1 documentation
Series.sort_values(*, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False, key=None)[source]#
🌐
Codecademy
codecademy.com › docs › python:pandas › dataframe › .sort_values()
Python:Pandas | DataFrame | .sort_values() | Codecademy
July 8, 2025 - ascending: Specifies whether the sort will be ascending or descending (True or False); defaults to True. inplace: By setting it to True, the operation will be performed on the original DataFrame and the function will return None; defaults to False. ...
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.25.3 › reference › api › pandas.DataFrame.sort_values.html
pandas.DataFrame.sort_values — pandas 0.25.3 documentation
Pandas arrays · Panel · Index objects · Date offsets · Frequencies · Window · GroupBy · Resampling · Style · Plotting · General utility functions · Extensions · Development · Release Notes · Enter search terms or a module, class or function name. DataFrame.sort_values(self, by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')[source]¶ ·
🌐
datagy
datagy.io › home › pandas tutorials › pandas dataframes › how to sort data in a pandas dataframe
How to Sort Data in a Pandas DataFrame • datagy
December 15, 2022 - This can be done by modifying the inplace= parameter. This parameter defaults to False; modifying it to True will allow the operation to occur in place. Let’s see what this looks like: # Sorting a DataFrame in place df.sort_values( by='sales', ...
🌐
GitHub
github.com › pandas-dev › pandas › issues › 15389
DataFrame.sort_values(inplace=True) is slow and eats too much memory · Issue #15389 · pandas-dev/pandas
February 14, 2017 - AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffPerformanceMemory or execution speed performanceMemory or execution speed performanceinplaceRelating to inplace parameter or equivalentRelating to inplace parameter or equivalent ... import pandas import numpy import resource import sys variant, nrows, ncols = sys.argv[1:4] numpy.random.seed(0) df = pandas.DataFrame(numpy.random.randn(int(nrows), int(ncols))) if variant == '1': df.sort_values(by=list(df.columns), inplace=True) elif v
Author   liori
🌐
Snowflake Documentation
docs.snowflake.com › en › developer-guide › snowpark › reference › python › 1.20.0 › modin › pandas_api › snowflake.snowpark.modin.pandas.DataFrame.sort_values
modin.pandas.DataFrame.sort_values | Snowflake Documentation
DataFrame.sort_values(by, axis=0, ascending=True, inplace: bool = False, kind='quicksort', na_position='last', ignore_index: bool = False, key: IndexKeyFunc | None = None)[source]¶
🌐
Sharp Sight
sharpsight.ai › blog › pandas-sort_values
How to use the Pandas sort_values method - Sharp Sight
July 24, 2021 - However, if you set inplace = True, the Pandas sort values method will directly sort the original DataFrame.
🌐
w3resource
w3resource.com › pandas › dataframe › dataframe-sort_values.php
Pandas DataFrame: sort_values() function - w3resource
DataFrame.sort_values(self, by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')
🌐
All About AI-ML
indhumathychelliah.com › 2020 › 09 › 29 › sorting-a-python-pandas-dataframes-by-index-and-value
Sorting a Python Pandas DataFrames by Index and Value – All About AI-ML
January 2, 2022 - We can sort pandas dataframes by row values/column values. Likewise, we can also sort by row index/column index. ... DataFrame.sort_values(by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False, key=None)