'Graph Sensor Data with Python and Matplotlib

I have a csv file like this:

sensor_name, time
bed, 01:08:40
bed, 01:09:33
bed, 01:09:51
bed, 01:11:06
kitchen, 01:27:57
kitchen, 01:30:03
living, 01:32:51
living, 01:33:06
living, 01:34:06
living, 01:35:06
living, 01:37:06
bed, 01:40:50
bed, 01:41:06
bed, 01:42:54
bed, 01:45:06
living, 01:50:30

In order to track movements, I just want to plot - with matplotlib - only the values where a sensor change occurs, thus the first and last before the change and eliminate the rest. The expected result looks like this:

sensor_name, time
bed, 01:08:40
bed, 01:11:06
kitchen, 01:27:57
kitchen, 01:30:03
living, 01:32:51
living, 01:37:06
bed, 01:40:50
bed, 01:45:06
living, 01:50:30

Thanks, all the best.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source