one two three
A ... ... ...
B ... ... ...
C ... ... ...
D ... ... ...
E ... ... ...
F ... ... ...
我想根据行索引标签是在一个列表中还是在另一个列表中来子集dataframe。这些列表是独占的,不包含相同的元素。
我可以用一张单子来做,但似乎不能用两张。
所以如果我有
list_A = ['A, B, F']
list_B = ['D']
所以
df[df.index.isin(list_A)]
one two three
A ... ... ...
B ... ... ...
F ... ... ...
我想要的是
df[df.index.isin(['A','B','D','F'])]
不合并列表:
one two three
A ... ... ...
B ... ... ...
D ... ... ...
F ... ... ...
但当我尝试
df[df.index.isin(list_A or List_B)]
df[df.index.isin(list_A) or df.index.isin(list_B)]
它不起作用。