If I have a number of files like this:

[![File Directory]](https://i.stack.imgur.com/qLxCc.png)

Inside each folder is 3 more like this:

[![File Directory 2]](https://i.stack.imgur.com/PPLoE.png)

Now inside each of these folders is a .txt file that looks like this:

[![.txt file]](https://i.stack.imgur.com/WoMFf.png)

For each of the .txt files I need to get the value from the 6th column in the file which I have circled in red and I am only interested in the lines that contain cope1, cope2, cope3, cope4 and cope5 at the start (highlighted in blue). Everything else can be ignored. 

I need to present the data separately for each folder

So would be:

[![result]](https://i.stack.imgur.com/v0VMr.png)

I need to read in the relevant data from each of the files and store it in a sensible data structure.

All the data I need to present like this so that I have the mean value for FFA cope 1 - cope 5
and so on for each of the 3 folders within each of the 10 folders. 

Presented roughly like this: 
[![Required Output](https://i.stack.imgur.com/eO1jK.png)](https://i.stack.imgur.com/eO1jK.png)

Apologies for the long winded question python newbie here! All help is greatly appreciated. 

```js
import os
import csv
import statistics

def main():
    values = {}
    ffaResults = {}
    lingualResults = {}
    ppaResults = {}

    dir = os.path.join("fmriroi", "roi_data")
    subdirs = os.listdir(dir)
    for subdir in subdirs:
        subdirpath = os.path.join(dir, subdir)
        subsubdirs = os.listdir(subdirpath)
        for subsubdir in subsubdirs:

            if subsubdir == "ffa":
                dirpath = os.path.join(subdirpath, subsubdir)
                files = os.listdir(dirpath)
                for filename in files:
                    path = os.path.join(dirpath, filename)
                    with open(path, "r") as f:
                        content = csv.reader(f, delimiter=" ")
                        for row in content:
                            if "cope" in row[1]:
                                name = row[1].split("/")[1]
                                if not name in values:
                                    ffaResults[name] = [float(row[6])]
                                else:
                                    ffaResults[name].append(float(row[6]))  

            if subsubdir == "lingual_gyrus":
                dirpath = os.path.join(subdirpath, subsubdir)
                files = os.listdir(dirpath)
                for filename in files:
                    path = os.path.join(dirpath, filename)
                    with open(path, "r") as f:
                        content = csv.reader(f, delimiter=" ")
                        for row in content:
                            if "cope" in row[1]:
                                name = row[1].split("/")[1]
                                if not name in lingualResults:
                                    lingualResults[name] = [float(row[6])]
                                else:
                                    lingualResults[name].append(float(row[6]))

            if subsubdir == "ppa":
                dirpath = os.path.join(subdirpath, subsubdir)
                files = os.listdir(dirpath)
                for filename in files:
                    path = os.path.join(dirpath, filename)
                    with open(path, "r") as f:
                        content = csv.reader(f, delimiter=" ")
                        for row in content:
                            if "cope" in row[1]:
                                name = row[1].split("/")[1]
                                if not name in ppaResults:
                                    ppaResults[name] = [float(row[6])]
                                else:
                                    ppaResults[name].append(float(row[6]))
    res = {}

    for k in ffaResults:
        res[k] = statistics.mean(values[k])
    print(res)

if __name__ == "__main__":
    main()
```

Output: required

[![Output](https://i.stack.imgur.com/wJ1i6.png)](https://i.stack.imgur.com/wJ1i6.png)