Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

IPython notebook Feb202.ipynb

Project: ETC
Views: 81
Kernel: Python 2 (SageMath)
%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
data['CO2'].plot()
<matplotlib.axes.AxesSubplot at 0x7f422c66cd90>
Image in a Jupyter notebook
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-2 10:35', '2015-02-2 12:10'), ('2015-02-4 10:35', '2015-02-4 12:10'), ('2015-02-9 10:35', '2015-02-9 12:10'), ('2015-02-11 10:35', '2015-02-11 12:10'), ('2015-02-16 10:35', '2015-02-16 12:10'), ('2015-02-18 10:35', '2015-02-18 12:10'), ('2015-02-23 10:35', '2015-02-23 12:10'), ('2015-02-25 10:35', '2015-02-25 12:10'), ) for begin, end in class_starts: process_data(begin, end, data, plot=True)
Start time = 2015-02-2 10:35 End time = 2015-02-2 12:10 Carbon dioxide rate of increase 1.45 ppm per minute Estimated number of students: 8 () Start time = 2015-02-4 10:35 End time = 2015-02-4 12:10 Carbon dioxide rate of increase 1.23 ppm per minute Estimated number of students: 7 () Start time = 2015-02-9 10:35 End time = 2015-02-9 12:10 Carbon dioxide rate of increase 3.14 ppm per minute Estimated number of students: 18 () Start time = 2015-02-11 10:35 End time = 2015-02-11 12:10 Carbon dioxide rate of increase 2.19 ppm per minute Estimated number of students: 12 () Start time = 2015-02-16 10:35 End time = 2015-02-16 12:10 Carbon dioxide rate of increase -1.97 ppm per minute Estimated number of students: -11 () Start time = 2015-02-18 10:35 End time = 2015-02-18 12:10 Carbon dioxide rate of increase 1.51 ppm per minute Estimated number of students: 9 () Start time = 2015-02-23 10:35 End time = 2015-02-23 12:10 Carbon dioxide rate of increase 5.48 ppm per minute Estimated number of students: 31 () Start time = 2015-02-25 10:35 End time = 2015-02-25 12:10 Carbon dioxide rate of increase 2.68 ppm per minute Estimated number of students: 15 ()
Image in a Jupyter notebook
begin = '2015-02-16 10:35' end = '2015-02-16 11:00' data['CO2'][begin:end].plot()
<matplotlib.axes.AxesSubplot at 0x7f422c709b90>
Image in a Jupyter notebook
num_students = np.array([8, 7, 18, 12, 9, 15])
np.mean(num_students)
11.5

title

some text