已知几组列名的左右端点,如何取出DataFrame中所有这些左右端点间的列?

df有如下的这些列,现在想要取出一系列两端点之间的列,例如取出col_a2, col_a76之间、col_d8, col_d50之间、col_e66, col_e90之间的所有列,怎么方便地实现?

df = pd.DataFrame(
     columns=['col_%s%d'%(j,i) for j in list('abcde') for i in range(100)])
search_begin = ['col_a2', 'col_d8', 'col_e66']
search_end = ['col_a76', 'col_d50', 'col_e90']
target = np.zeros(df.shape[1])
target[df.columns.get_indexer_for(search_begin)] = 1
target[df.columns.get_indexer_for(search_end)+1] = 1
df.loc[:, target.cumsum()%2==1]
1赞

非常感谢!巧妙的方案