0

I was doing something like this, enter image description here

Is there a way that I can read them all at once?

  • I think you might need to put them in the same folder. Reference [here](https://stackoverflow.com/questions/20906474/import-multiple-csv-files-into-pandas-and-concatenate-into-one-dataframe) – Prince Dec 16 '21 at 22:23
  • Welcome to SO! Please don't add data or code as images. Instead copy the code directly to the post. This will make it much more likely that someone is quickly able to help you. – buddemat Dec 23 '21 at 11:48

1 Answers1

0

I would personally do a dict comprehension for this

root = "drive/Mydrive/"

goodvariable = {f"subject{num}": 
{'running': pd.read_csv(f'{root}data/subject_{num}/acc_running_chest.csv'),
'walking': pd.read_csv(f'{root}data/subject_{num}/acc_walking_chest.csv'),
'climbdown': pd.read_csv(f'{root}data/subject_{num}/acc_climbingdown_chest.csv'),
'climbup': pd.read_csv(f'{root}data/subject_{num}/acc_climbingup_chest.csv')}
for num in range(1, 10)
}

In place of 10, a different number can be entered, depending on the number of subjects you have + 1 so if you had 100 subjects, you would have to enter 101. I used 10 because of the image that was supplied (there were 9 subjects, 9+1 = 10). This dict comprehension should give you a dictionary of this structure:

{
"subject1": {
           "running": csv_read data from acc_running_chest for subject 1,
           "walking": csv_read data from acc_walking_chest for subject 1,
           "climbdown": csv_read data from acc_climbingup_chest for subject 1,
           "climbup": csv_read data from acc_climbingup_chest for subject 1 

            },
"subject2": {

                ... and so on

             }

}

You can then access it with:

goodvariable['subject1']['walking'] # csv data of acc_walking_chest for subject 1
Rose
  • 713
  • 2
  • 8