Select rows in pandas MultiIndex DataFrame

What are the most common pandas ways to select/filter rows of a dataframe whose index is a MultiIndex? Slicing based on a single value/label Slicing based on multiple labels from one or more levels Filtering on boolean conditions and expressions Which methods are applicable in what circumstances Assumptions for simplicity: input dataframe does not have … Read more

Converting a Pandas GroupBy output from Series to DataFrame

I’m starting with input data like this df1 = pandas.DataFrame( { “Name” : [“Alice”, “Bob”, “Mallory”, “Mallory”, “Bob” , “Mallory”] , “City” : [“Seattle”, “Seattle”, “Portland”, “Seattle”, “Seattle”, “Portland”] } ) Which when printed appears as this: City Name 0 Seattle Alice 1 Seattle Bob 2 Portland Mallory 3 Seattle Mallory 4 Seattle Bob 5 … Read more