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

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.