如何使用正则表达式过滤删除一些数据框列,但保留其他包含某些字符的列?

How do I remove some data frame columns using regular expressions filtering but keep others that contain some of the characters?

我需要从 pandas 数据框中删除包含特定字符串模式 (.1) 的 headers 列。到目前为止,我的代码执行了此操作,但也删除了 headers 包含模式 11 的列,我想保留它:

DX_totals = DX_totals[DX_totals.columns.drop(list(DX_totals.filter(regex='[.|1]{2}')))]

如何调整代码以仅删除 headers 包含模式 .1 的列?

数据格式为:

Well ID PlantFlow   PlantChrome DXRunTime   ME01    ME02    ME03    ME04    ME05    ME06    ... MJ22.1  MJ23.1  MJ24.1  MJ25.1  MJ26.1  MJ27.1  MJ28.1  MJ29.1  MJ30.1  DX
0   2021-01-01 00:01:00 91668344    5426653 22092   980729  1117150 103164  287075  2747259 1885657 ... -44.115395  -40.537468  0   -31.149002  -61.727837  0   0   -68.037201  -63.994675  22092
1   2021-01-02 00:00:00 92506192    5471052 22332   993835  1131376 0   0   2777229 0   ... -44.074005  -40.616493  0   -32.239822  -61.803848  0   0   -68.023262  -63.993423  22332
2   2021-01-03 00:00:00 93343920    5515476 22572   1006940 1145596 0   0   2807222 0   ... -43.943542  -40.857651  0   -31.181437  -61.927658  0   0   -68.01889   -63.997154  22572

期望的结果如下:

Well ID PlantFlow   PlantChrome DXRunTime   ME01    ME02    ME03    ME04    ME05    ME06    ME11  ...
0   2021-01-01 00:01:00 91668344    5426653 22092   980729  1117150 103164  287075  2747259 2748354 ...
1   2021-01-02 00:00:00 92506192    5471052 22332   993835  1131376 0   0   2777229 0   2777350 ...

谢谢!

我用你的一些 headers:

创建了一个虚拟 df
df = pd.DataFrame({'ME01': ['dummy0'], 'ME04': ['dummy1'], 'ME05': ['dummy2'], 'MJ22.1': ['dummy3'], 'MJ24.1': ['dummy4']})

然后改成regex:

df[df.columns.drop(list(df.filter(regex=r'\.1')))]

输出: