Python 使用正则表达式筛选数据帧列
我统计数据集的统计数据,并希望筛选包含特定字符串的列。我怎么能用正则表达式呢 在Python 使用正则表达式筛选数据帧列,python,regex,pandas,Python,Regex,Pandas,我统计数据集的统计数据,并希望筛选包含特定字符串的列。我怎么能用正则表达式呢 在volumes\u c中,我筛选了一些结构,其中包含卷名 Select_list = ["Amygdala", "Hippocampus", "Lateral-Ventricle", "Pallidum", "Putamen", "Thalamus", "Caudate"] Side = ["Left", "Right"] #Selected columns if(Select_list): for s in
volumes\u c
中,我筛选了一些结构,其中包含卷名
Select_list = ["Amygdala", "Hippocampus", "Lateral-Ventricle", "Pallidum", "Putamen", "Thalamus", "Caudate"]
Side = ["Left", "Right"]
#Selected columns
if(Select_list):
for s in Side:
for struct in Select_list:
volumes_c = group_c.filter(regex="^(?=.*"+s+")(?=.*"+struct+")(?=.*Volume)")
现在,我想在以下位置筛选包含surfare
的列:
假设数据帧数据位于变量df中,则过滤器将为:
df.filter(like="SurfArea", axis=1)
实际上,“axis”arg有一个默认值1,您可以忽略它,但如果要按行筛选,请将其设置为0。