Pandas MultiIndex: Select rows by the outer level with loc

Pandas MultiIndex: Select rows by the outer level with loc

To retrieve all rows from a multi-indexed Python Pandas data frame or series based on the outermost index, use “loc”:

(
  pd
 .read_parquet('/Users/reuven/Data/nyc_taxi_2025-11.parquet')
 .groupby(['passenger_count', 'VendorID'])['total_amount'].mean()
 .loc[1.0]
)