#!/usr/bin/env python # coding: utf-8 # In[1]: import pandas as pd import sys get_ipython().run_line_magic('matplotlib', 'inline') # In[2]: print('Python version ' + sys.version) print('Pandas version ' + pd.__version__) # # Sort # ### How do I sort a column ascending? # In[3]: # dataframe df = pd.DataFrame(data={'col1':[0,10,2,30,4]}) df # In[4]: # Sort by col1 ascending df.sort_values(by='col1') # ### How do I sort by the index? # In[5]: # Unordered index d = {'col2':[22,10,113]} i = [pd.Timestamp('20130102'), pd.Timestamp('2013-01-01'), pd.Timestamp('1/3/2013')] df = pd.DataFrame(data=d, index = i) df # In[6]: # Index sorted ascending df.sort_index() #
This tutorial was created by HEDARO