Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

Well, I am new to data science and I am working on python where I had to prase multiple files and plot a graph out of it. I have researched it and found that global function can achieve the results but I don't know how to use it.

My file goes like this as shown below:

PRA-DIA_8.1_A_1.stat0, PRA-DIA_8.1_A_1.stat1, PRA-DIA_8.1_A_1.stat3....

When I am working on a single file, I have no issues. But when I try to use multiple files I am not able to get the results.

1 Answer

0 votes
by (36.8k points)

I am assuming that you are located inside the directory and providing the code below which file the file starting with the name PRA-DIA_8.1_A_1.sta*

import glob

file_paths = glob.glob("./PRA-DIA_8.1_A_1.sta*")

Since we have all the files we can parse the file using the code below

for file_path in file_paths:

    with open(file_path, "r") as f:

        file_content = f.read()

        ...  # do your supplementary parsing here

If you want to know more about the Data Science then do check out the following Data Science link which will help you in understanding Data Science from scratch 

Browse Categories

...