forked from snychka/python-decoding-sensor-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_data.py
More file actions
35 lines (27 loc) · 1.23 KB
/
Copy pathload_data.py
File metadata and controls
35 lines (27 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# At the top of the file, create three import statements
# for os, glob, and csv.
# These libraries will allow us to work with a collection of files.
import os
import glob
import csv
def load_sensor_data():
sensor_data=[]
sensor_files = glob.glob(os.path.join(os.getcwd(), 'datasets', '*.csv'))
#Create one for loop that loops through sensor_files
# using sensor_file as the iterator variable.
# In the with body, set a variable called data_reader
# equal to csv.DictReader().
# Pass in the current data_file as the first argument,
# and set the delimiter=',' as the second argument.
# The data_reader will contain a list of
# dictionaries with the sensor data.
for sensor_file in sensor_files:
with open(sensor_file) as data_file:
data_reader = csv.DictReader(data_file, delimiter=',')
#Inside the body of the second for loop, append each
# row record to the sensor_data list (you created this list earlier in the Create a Function to Parse the Data task).
for row in data_reader:
sensor_data.append(row)
#Finally, your function should return sensor_data
# (outside of all for loops, and the very end of the function).
return sensor_data