在Pandas中,我们可以按名称和正则表达式选择列吗?

假设我的熊猫数据框如下:

import pandas as pd

df = pd.DataFrame(
    dict(ID = [1, 2, 3],
         xz = [0, 1, 1],
         yz = [4, 5, 6],
         yx = [7, 11, 18],
         xy = [10, 10, 11])
)

If I want to select all those columns whose names contain an x, I could do the following:

df.filter(regex = '.*x.*', axis=1)

如果我也想按列名进行选择,则需要执行以下操作,该操作将无效。

df.filter(items = ['ID'], regex = '.*x.*', axis=1)

这是行不通的,因为

TypeError: Keyword arguments `items`, `like`, or `regex` are mutually exclusive`

这是可行的替代方法。

df.iloc[:,df.columns.str.contains('x') | 
          df.columns.str.match('ID')]

有更好或更推荐的方法吗?

I am aware how painlessly this can be done using R/tidyverse, i.e. Df %>% select(ID, contains('x')). I am also aware of siuba and dplython etc that implement much of dplyr's functionality with Pandas. What I am asking here is about the recommended "base Pandas" way of doing this?