0

I count statistics for the dataset, and I want to filter columns that contain specific strings. How I could do it with regex?

Here in volumes_c I filtered some structures, that have Volume in there names

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)")

Now i want to filter columns that contain SurfArea in:

SurfArea

funie200
  • 3,688
  • 5
  • 21
  • 34
  • duplicate of https://stackoverflow.com/questions/21285380/find-column-whose-name-contains-a-specific-string – VnC May 23 '19 at 12:39

1 Answers1

1

Suppose DataFrame data is in the variable df, so the filter will be:

 df.filter(like="SurfArea", axis=1)

Actually, 'axis' arg has a default value 1 and you can omit it, but if you want to filter by rows set it up as 0.

greg
  • 1,417
  • 9
  • 28