Title: Sorting Rows In pandas Dataframes
Slug: pandas_sorting_rows_dataframe
Summary: Sorting Rows In pandas Dataframes
Date: 2016-05-01 12:00
Category: Python
Tags: Data Wrangling
Authors: Chris Albon
In [22]:
import pandas as pd
In [23]:
data = {'name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'year': [2012, 2012, 2013, 2014, 2014],
'reports': [1, 2, 1, 2, 3],
'coverage': [2, 2, 3, 3, 3]}
df = pd.DataFrame(data, index = ['Cochice', 'Pima', 'Santa Cruz', 'Maricopa', 'Yuma'])
df
Out[23]:
In [24]:
df.sort_values(by='reports', ascending=0)
Out[24]:
In [25]:
df.sort_values(by=['coverage', 'reports'])
Out[25]: