You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The dataset for this project is stored in several CSV files found in the `dataset` folder. It represents the data collected from a device with multiple sensors. The records include measurements of temperature, humidity, energy consumption, and particle count in the air over a given area. The data is collected over a period of 24 hours.
27
28
28
29
To start, open the file called `load_data.py` in the `sensor` folder - the rest of the tasks in this module happen in this same file.
29
30
30
31
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.
31
32
32
-
### Task 2: Create a Function to parse the data
33
+
---
34
+
To test this module locally:
35
+
36
+
- Open a terminal at the root of the project
37
+
- Run the command `pytest -k module1`
38
+
39
+
### M1: Task 2: Create a Function to parse the data
Create a method called `load_sensor_data` that takes no arguments.
37
-
In the body of the `load_sensor_data` function, create variable called `sensor_data` and set it as an empty `list` - the rest of the tasks in this module happen in this function.
43
+
Create a function called `load_sensor_data` that takes no arguments.
44
+
In the body of the `load_sensor_data` function, create variable called `sensor_data` and set it as an empty `list`.
Below the `sensor_data` variable create another variable called `sensor_files` that is set to a call to the `glob.glob()` function.
56
+
Next, create a variable called `sensor_files` that is set to a call to the `glob.glob()` function.
44
57
45
-
Pass `glob` function a single argument, a call to the `os.path.join()` function. In turn pass `os.path.join()` three arguments: `os.getcwd()`, `datasets`, and `*.csv`.
58
+
Pass the glob function a single argument, a call to the `os.path.join()` function.
46
59
47
-
The `datasets` argument corresponds to the folder with your sensor data. The data files are in `csv` format. You may open them and explore the content of the records in them.
60
+
In turn pass `os.path.join()` three arguments: `os.getcwd()`, `"datasets"`, and `"*.csv"`.
The `sensor_files` object contains a list of file names i.e. ['SENSOR_ROOM2', 'SENSOR_ROOM1']
79
+
80
+
To read the sensor data of these files, five steps are required:
81
+
82
+
1) Create one `for` loop that loops through `sensor_files` using `sensor_file` as the iterator variable.
83
+
84
+
2) In the body of this loop use a `with` statement to `open` the `sensor_file` and set the alias to `data_file`.
85
+
86
+
3) 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.
87
+
88
+
4) Create a second `for` loop to `data_file` to get access to each record. Use `row` as your iterator variable.
89
+
90
+
5) Inside the body of the second `for` loop, append each `row` record to the `sensor_data` list created on `Task 2`
91
+
92
+
Finally, your function should return `sensor_data` list containing a list of dictionaries.
), "Are you creating a variable called `sensor_files` and assigning it glob.glob() and passing os.path.join()? Are you passing 3 values to os.path.join()?"
0 commit comments