Advertisement
elena1234

multiple indexes in Python

Jan 4th, 2023 (edited)
894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | Source Code | 0 0
  1. filter1 = cars.index.get_level_values('model_year') == 76
  2. filter2 = cars.index.get_level_values('origin') == 'japan'
  3. cars.loc[filter1 & filter2]
  4.  
  5. ##############################################################
  6. cars.query('model_year == 75')
  7.  
  8. ##############################################################
  9. cars.loc[([77,79], "japan"), ["mpg", "name"]]
  10.  
  11. ###############################################################
  12. cars = cars.swaplevel().sort_index(ascending = True)
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement