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 ?

Mr.Riply
  • 665
  • 1
  • 7
  • 29
Anja
  • 325
  • 4
  • 16
  • Does this answer your question? [Select by partial string from a pandas DataFrame](https://stackoverflow.com/questions/11350770/select-by-partial-string-from-a-pandas-dataframe) – Cleb Nov 06 '19 at 14:40

1 Answers1

1

Try:

df[df.structure_id_path.str.contains('/315/')]
Aryerez
  • 2,581
  • 2
  • 4
  • 14
  • 1
    @Anja: If it answers your question, please accept the answer by clicking the small check next to it which then turns green. – Cleb Nov 06 '19 at 15:05
  • 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 Nov 18 '19 at 11:20
  • @Anja Since your numbers always come between "/", I added those to the string in search – Aryerez Nov 18 '19 at 11:26