In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
data = pd.read_csv('February',
                   skiprows=3,       # ignore the first 3 rows of data
                   sep=';',          # semicolon is used to separate data values
                   index_col=1,      # use column 1 as the dates to index the data
                   parse_dates=True) # convert the date string into a date object
In [2]:
data['CO2'].plot()
Out[2]:
<matplotlib.axes.AxesSubplot at 0x7fda0812e050>
In [3]:
def process_data(begin, end, data, plot=False):
    x = data['Timestamp'][begin:end]
    x = x - x[0]
    y = data['CO2'][begin:end]

    fit = np.polyfit(x,y,1)
    room_ppm_per_second = fit[0]
    room_ppm_per_minute = room_ppm_per_second * 60
    ppm_per_student_per_minute = 0.176
    num_students = room_ppm_per_minute / ppm_per_student_per_minute

    if plot:
        yfit = np.polyval(fit, x)
        plt.plot(x, y)
        plt.plot(x, yfit)
        plt.xlabel ("seconds")
        plt.ylabel ("ppm")

    print('Start time = {}'.format(begin))
    print('End time = {}'.format(end))
    print('Carbon dioxide rate of increase {:.2f} ppm per minute'.format(room_ppm_per_minute))    
    print('Estimated number of students: {:.0f}'.format(num_students))
    print()

class_starts = (
                ('2015-02-3 9:50', '2015-02-3 12:10'),
                ('2015-02-5 9:50', '2015-02-5 12:10'),
                ('2015-02-10 9:50', '2015-02-10 12:10'),
                ('2015-02-12 9:50', '2015-02-12 12:10'),
                ('2015-02-17 9:50', '2015-02-17 12:10'),
                ('2015-02-19 9:50', '2015-02-19 12:10'),
                ('2015-02-24 9:50', '2015-02-24 12:10'),
                ('2015-02-26 9:50', '2015-02-26 12:10'),
               )

for begin, end in class_starts:
    process_data(begin, end, data, plot=True)
Start time = 2015-02-3 9:50
End time = 2015-02-3 12:10
Carbon dioxide rate of increase 1.83 ppm per minute
Estimated number of students: 10
()
Start time = 2015-02-5 9:50
End time = 2015-02-5 12:10
Carbon dioxide rate of increase 4.79 ppm per minute
Estimated number of students: 27
()
Start time = 2015-02-10 9:50
End time = 2015-02-10 12:10
Carbon dioxide rate of increase 5.25 ppm per minute
Estimated number of students: 30
()
Start time = 2015-02-12 9:50
End time = 2015-02-12 12:10
Carbon dioxide rate of increase 3.65 ppm per minute
Estimated number of students: 21
()
Start time = 2015-02-17 9:50
End time = 2015-02-17 12:10
Carbon dioxide rate of increase 6.52 ppm per minute
Estimated number of students: 37
()
Start time = 2015-02-19 9:50
End time = 2015-02-19 12:10
Carbon dioxide rate of increase 3.58 ppm per minute
Estimated number of students: 20
()
Start time = 2015-02-24 9:50
End time = 2015-02-24 12:10
Carbon dioxide rate of increase 4.60 ppm per minute
Estimated number of students: 26
()
Start time = 2015-02-26 9:50
End time = 2015-02-26 12:10
Carbon dioxide rate of increase -0.06 ppm per minute
Estimated number of students: -0
()

In []: