首页 > 解决方案 > Pandas: Applying '&' operator in df.query(), in mutiindex scenario

问题描述

How to use the & operator in df.query() for same index in multi-index data frame. e.g in my data frame named 'movie_genre'.

I have three indexes -> [id, title, genre]. Now I want to access all the id & title wherein genre is 'Comedy' & 'Drama'. I am using

df.query('(genre=="Comedy") & (genre=="Drama")') 

but it is returning blank result.

标签: pandasmulti-index

解决方案


推荐阅读