Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to search for a specific word within a text?

I have a file, of type txt, with the following text:

The dataset is available at: https://archive.ics.uci.edu/ml/datasets.php
The file name is Cancer_Data.xml
This is one of three domains provided by the Oncology Institute that has repeatedly appeared in the machine learning literature.

I need to search within this text the word that accompanies the "xml". I tried to do the following implementation:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

      import pandas as pd

      with open(local_arquivo, "r") as file_read:   
          for line in file_read:        
              var_split = line.split()
              for i in range(0, len(var_split)):
                  if(var_split[i].str.contains('xml')):
                      archive_name = var_split.iloc[i]   

The idea was to separate the text using the split function and then look for the part that contains the ‘xml’. However, when I run it, the following error appears:

        AttributeError: 'str' object has no attribute 'str'

I would like the output to be:

archive_name = Cancer_Data.xml

>Solution :

Try

if('xml' in var_split[i]):

source: https://docs.python.org/3/reference/expressions.html#in

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading