Selecting and slicing date and time related data can be quite different compared to the other kind of data. By setting the datetime object as an index (DatetimeIndex), this will make slicing easier. We will see numerous methods that only work with a DatetimeIndex.
When we are dealing with data depending on date and time parameter, it can be useful to make those data as the index. Here, we convert the date in our data into a Timestamp object then set it up as the index. This index will become a DatetimeIndex object.
Selecting all the rows with a particular index can be done by using the .loc indexing operator. With a Timestamp in the index, we can select all rows that partially match an index value. Using .shape, we can also find out the size of that particular slice of data.
Grouping according to some period of time can be easily done by using resample method. Then, you can apply numerous DataFrame method to obtain the information you want.
DatetimeIndex itself has many of the same atttributes and methods as a pandas Timestamp. Let's take a look at some that they have in common.
A. Analyzing Temperature
Save the data on Feb 2, 2015 in a variable. Then, save the temperature on that day in a variable then print it out.
B. When is the light off?
The new dataset light_off contains all the data when the column Light is 0. Save the hour of day (0 - 23) of this data in a csv file named light_off_data.csv.
C. Anyone in the room?
We suspect that when CO2 level is high, there's a person in the room. From Feb 3, 2015 at 6 am to 6 pm, save the maximum value of CO2 per 10 minutes (600 seconds) in a csv file named max_co2.csv.
D. New Dataset
Separate the day, hour, and minutes from the original dataset. Then, combine them together with temperature, humidity, and CO2 level. Save it in a new dataset called room_stats2.csv.