Skip to content

Instantly share code, notes, and snippets.

@lakshay-arora
Created April 8, 2020 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lakshay-arora/342b7fcba8d69d96f37080ae253b5e05 to your computer and use it in GitHub Desktop.
Save lakshay-arora/342b7fcba8d69d96f37080ae253b5e05 to your computer and use it in GitHub Desktop.
# create a list to store the dataframes
dataframe_list = []
# iterate through folder 1 to 34
for folder in range(1, 35):
# try we are able to read the file
try :
### notice that for folder i, we have file name "region_i"
### create the file name
file_name = 'region_' + str(folder) + '.csv'
### read the file if possible
data = pd.read_csv('dataset/'+ str(folder) +'/' +file_name)
dataframe_list.append(data)
# if any error occurs, skip this step and continue reading other files.
except FileNotFoundError:
print('File not found!!', file_name)
# If any other error occurs, print the file name
except Exception:
print('Another Error!!', file_name)
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment