Python 筛选出包含特定单词的列

Python 筛选出包含特定单词的列,python,pandas,dataframe,Python,Pandas,Dataframe,在pandas数据框中,我需要过滤掉那些包含单词“fixed”的列。然后我想创建另一个仅包含这些列的数据帧。我该怎么做 cols = dataset.columns split = lambda x: [c for c in x.split('_') if c.startswith('fixed')] 只需使用以下属性: fixed = [c for c in dataset.columns if c.startswith("fixed")] fixed_dataset = dataset.

在pandas数据框中,我需要过滤掉那些包含单词“fixed”的列。然后我想创建另一个仅包含这些列的数据帧。我该怎么做

cols = dataset.columns

split = lambda x: [c for c in x.split('_') if c.startswith('fixed')]
只需使用以下属性:

fixed = [c for c in dataset.columns if c.startswith("fixed")]
fixed_dataset = dataset.ix[:, fixed]
同样,对于相反的情况:

non_fixed = [c for c in dataset.columns if not c.startswith("fixed")]
dataset.ix[:, non_fixed]
只需使用以下属性:

fixed = [c for c in dataset.columns if c.startswith("fixed")]
fixed_dataset = dataset.ix[:, fixed]
同样,对于相反的情况:

non_fixed = [c for c in dataset.columns if not c.startswith("fixed")]
dataset.ix[:, non_fixed]

不要使用
split=lambda…
<代码>lambda函数未命名,因此不要给它们命名。这是违反PEP 8的。不要使用
split=lambda…
<代码>lambda函数未命名,因此不要给它们命名。这是反对政治公众人物8号的。