您可以反转以下结果
str.endswith:
In[13]:df.loc[~df.index.str.endswith('_test')]Out[13]: col1 col2entry_1 10 11entry_3 14 15或者,将最后5个字符切成薄片,然后使用进行比较
!=:
In[13]:df.loc[df.index.str[-5:]!='_test']Out[18]: col1 col2entry_1 10 11entry_3 14 15
仍然可以
filter通过传递正则表达式模式来过滤不以结尾的行
'_test':
In[25]:df.filter(regex='.*[^_test]$', axis=0)Out[25]: col1 col2entry_1 10 11entry_3 14 15
正如@ user3483203所指出的,最好使用以下正则表达式:
df.filter(regex='.*(?<!_test)$', axis=0)



