Slice pandas multiindex dataframe using list of index values [duplicate]
问题 This question already has answers here : Select rows in pandas MultiIndex DataFrame (2 answers) Closed 12 months ago . I have a multi-index dataframe that looks like uid tid text abc x t1 bcd y t2 uid and tid are the indexes. I have a list of uid s, and want to get the rows corresponding to the uids in that list, but keeping the 2nd level index values (tid). I want to do it without running any explicit loop. Is that possible? 回答1: Data: L = ['abc', 'bcd'] print (df) text uid tid abc x t1 abc1