0

I have a pandas dataframe in which I have 1300 brain parts with 21 columns of information about them. In there is a structure_id_path, a tree-like structure of brain regions. I want to find every structure_id_path that contains e.g. '315' in it.

import pandas as pd
import numpy as np
df = pd.read_csv('/home/anja/Schreibtisch/Master/vonIsa/structure_tree_safe_2017.csv')

df[df.structure_id_path == '/997/8/567/688/695/315/184/526157192/'] 

When I do it like that I find exactly that one brain part with that specific structure_id_path.

But if I want to find every structure_id_path that contains 315, it returns an empty dataFrame, because it can't find 315.

isocortex = '315'
x = structure_list[structure_list['structure_id_path'] == isocortex]

Is there a method to find it, like *315 ?

1

1 Answer 1

1

Try:

df[df.structure_id_path.str.contains('/315/')]
Sign up to request clarification or add additional context in comments.

3 Comments

@Anja: If it answers your question, please accept the answer by clicking the small check next to it which then turns green.
I have now the problem that it also finds '1315' but I only want to find exactly '315'. Do you know how I can do this?
@Anja Since your numbers always come between "/", I added those to the string in search

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.