Skip to content

Commit 295dcbf

Browse files
Add files via upload
1 parent b71c587 commit 295dcbf

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

Clean.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Created on Wed Jul 5 11:11:08 2023
3+
@author: Pradeep Kumar
4+
"""
5+
6+
from datetime import time
7+
8+
def remove_ten_to_fourthirty(sensor_data):
9+
"""
10+
Removes the data between 10:00 PM and 4:30 AM.
11+
12+
Args:
13+
sensor_data (pd.DataFrame): Raw sensor data.
14+
15+
Returns:
16+
pd.DataFrame: Cleaned data.
17+
"""
18+
sensor_data['Temp Time'] = sensor_data.time.dt.time
19+
clean_data = sensor_data[(sensor_data['Temp Time'] >= time(4, 30)) & (sensor_data['Temp Time'] <= time(22, 0))]
20+
clean_data = clean_data.drop(columns=['Temp Time'])
21+
22+
return clean_data
23+
24+
25+
def remove_sleep_hour(sensor_data_s):
26+
"""
27+
Removes timestamps with 'Sleeping' as a primary activity.
28+
29+
Args:
30+
sensor_data (pd.DataFrame): Raw sensor data.
31+
32+
Returns:
33+
pd.DataFrame: Cleaned data.
34+
"""
35+
sensor_data_s['PRIMARY activity'] = sensor_data_s['PRIMARY activity'].str.strip()
36+
clean_data_s = sensor_data_s[sensor_data_s['PRIMARY activity'] != '1 Sleeping']
37+
clean_data_s = clean_data_s[clean_data_s['PRIMARY activity'] != '9']
38+
return clean_data_s
39+
40+
41+
def remove_if_secondary_activity(sensor_data):
42+
"""
43+
Removes rows if a secondary activity exists.
44+
45+
Args:
46+
sensor_data (pd.DataFrame): Raw sensor data.
47+
48+
Returns:
49+
pd.DataFrame: Cleaned data.
50+
"""
51+
sensor_data['Doing anything else while you did the PRIMARY activity/activities'] = sensor_data['Doing anything else while you did the PRIMARY activity/activities'].str.strip().str.upper()
52+
clean_data = sensor_data[sensor_data['Doing anything else while you did the PRIMARY activity/activities'] != 'YES']
53+
return clean_data
54+
55+
56+
def remove_if_other_activity(sensor_data):
57+
"""
58+
Removes rows if 'Specify the other activity' is nonzero.
59+
60+
Args:
61+
sensor_data (pd.DataFrame): Raw sensor data.
62+
63+
Returns:
64+
pd.DataFrame: Cleaned data.
65+
"""
66+
clean_data = sensor_data[sensor_data['Specify the other activity'] == 0]
67+
return clean_data

0 commit comments

Comments
 (0)