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)