<jupyter_start><jupyter_text>Analyzing<jupyter_code>print("Hello world")
# print "Hello world"
import numpy
numpy.loadtxt(fname = 'data/inflammation-01.csv', delimiter = ',')
weight_kg = 55
weight_kg = 57.5
weight_lbs = 2.2*weight_kg
print('weight in kg', weight_kg, 'weight in lbs', weight_lbs)
a = 3
b = a
print(a)
print(b)
a = 5
print(a)
print(b)
a = [1, 2, 3]
b = a
print(a)
print(b)
a[0] = 5
print(a)
print(b)
a = 'abc'
print(a)
print(b)
a = [1, 2, 3]
b = a.copy()
print(a)
print(b)
a[0] = 5
print(a)
print(b)

data = numpy.loadtxt(fname = 'data/inflammation-01.csv', delimiter = ',')
print(type(data))
data.shape
data.size
data.max()
numpy.max(data)
data[0, 0]
data[30, 20]
print(data)
'a'
'b'
'c'
print('a')
print('b')
print('c')
data[5:10, 0:10]
data[5:10, :10]
data[5:10, 30:]
data[:][0]
data[5:10, -3:-1]<jupyter_output><empty_output><jupyter_text>Operating on array<jupyter_code>print('times2', data*2.)
print('original', data)
data+data<jupyter_output><empty_output><jupyter_text>Methods<jupyter_code>print(data.max())
print(data.min())
print(data.mean())<jupyter_output>20.0
0.0
6.14875<jupyter_text>ExerciseFind the standard deviation of data<jupyter_code>data.std?
help(data.std)
print(data.std())
print(numpy.std(data))<jupyter_output>4.61383319712
4.61383319712<jupyter_text>60 patients, 40 days<jupyter_code>data[1, :].mean()
numpy.mean(data[1])
print(data.max(axis = 1))
print(data.max(axis = 1).shape)
#%matplotlib 
#%matplotlib notebook
%matplotlib inline
import matplotlib
image = matplotlib.pyplot.imshow(data)
ave_inflammation = data.mean(axis = 0)
ave_inflammation.shape
ave_plot = matplotlib.pyplot.plot(ave_inflammation)
fig = matplotlib.pyplot.figure(figsize = (10.0, 3.0))
mean_axis = fig.add_subplot(1, 3, 1)
max_axis = fig.add_subplot(1, 3, 2)
min_axis = fig.add_subplot(1, 3, 3)

mean_axis.plot(data.mean(axis = 0))
max_axis.plot(data.max(axis = 0))
min_axis.plot(data.min(axis = 0))

mean_axis.set_ylabel('Mean')
mean_axis.set_xlabel('Day')

max_axis.set_ylabel('Max')
max_axis.set_xlabel('Day')

min_axis.set_ylabel('Min')
min_axis.set_xlabel('Day')

fig.tight_layout()
import numpy as np
from matplotlib import pyplot as plt
plt.plot(ave_inflammation)<jupyter_output><empty_output><jupyter_text>ExercisePlot Standard deviation  of the inflammation data for each day across all patients<jupyter_code>plt.plot(data.std(axis = 0))
plt.ylabel('Standard Deviation')
fig = plt.figure()
std_axis = fig.add_subplot(1,1,1)
std_axis.plot(data.std(axis = 0))
std_axis.set_ylabel('Standard Deviation')<jupyter_output><empty_output><jupyter_text>Loops<jupyter_code>ls data/*.csv
word = 'lead'
print(word[0])
print(word[1])
print(word[2])
print(word[3])
for letter in word:
    print(letter)
print(letter)
for num in np.arange(4, 9, 1):
    print(num)
len(word)
len(np.arange(4, 9, 1))<jupyter_output><empty_output><jupyter_text>Exercise:<jupyter_code>5**3<jupyter_output><empty_output><jupyter_text>Use a for loop to calculate 5^3<jupyter_code>s = 5
for i in range(0, 2, 1):
    s = s*5
print(s)
range(0, 2, 1)
original_num = 1.0
for time in [0, 1, 2]:
    original_num = original_num * 5
print(original_num)
original_num = 1.0
for time in np.arange(0, 3, 1):
    original_num *= 5
print(original_num)
np.arange(3)<jupyter_output><empty_output><jupyter_text>List<jupyter_code>odd = [1, 3, 5]
odd[1]
odd*2
odd + [4]
odd[-1]
odd
odd.append(7)
print(odd)
odd.reverse()
print(odd)
test = odd.reverse()
print(test)<jupyter_output>None<jupyter_text>Analyzing data from multiple files<jupyter_code>import glob
filelist = glob.glob('data/*.csv')
print(filelist)<jupyter_output>['data/inflammation-01.csv', 'data/inflammation-02.csv', 'data/inflammation-03.csv', 'data/inflammation-04.csv', 'data/inflammation-05.csv', 'data/inflammation-06.csv', 'data/inflammation-07.csv', 'data/inflammation-08.csv', 'data/inflammation-09.csv', 'data/inflammation-10.csv', 'data/inflammation-11.csv', 'data/inflammation-12.csv', 'data/small-01.csv', 'data/small-02.csv', 'data/small-03.csv']<jupyter_text>Exercise:Copy and paste the code to make 3 plots and use glob and a for loop to make plots of the mean, max, min, values for the first 3 files<jupyter_code>filenames = glob.glob('data/*.csv')
for ifile in filenames[0:3]:
    print(ifile)
    data = np.loadtxt(fname = ifile, delimiter = ',')
    fig = matplotlib.pyplot.figure(figsize = (10.0, 3.0))
    
    mean_axis = fig.add_subplot(1, 3, 1)
    max_axis = fig.add_subplot(1, 3, 2)
    min_axis = fig.add_subplot(1, 3, 3)

    mean_axis.plot(data.mean(axis = 0))
    max_axis.plot(data.max(axis = 0))
    min_axis.plot(data.min(axis = 0))

    mean_axis.set_ylabel('Mean')
    mean_axis.set_xlabel('Day')

    max_axis.set_ylabel('Max')
    max_axis.set_xlabel('Day')

    min_axis.set_ylabel('Min')
    min_axis.set_xlabel('Day')

    fig.tight_layout()
    plt.show()
filenames = glob.glob('data/*.csv')
for indx, ifile in enumerate(filenames):
    print(indx, ifile)
for indx, ifile in zip(np.arange(len(filenames)), filenames):
    print(indx, ifile)<jupyter_output>0 data/inflammation-01.csv
1 data/inflammation-02.csv
2 data/inflammation-03.csv
3 data/inflammation-04.csv
4 data/inflammation-05.csv
5 data/inflammation-06.csv
6 data/inflammation-07.csv
7 data/inflammation-08.csv
8 data/inflammation-09.csv
9 data/inflammation-10.csv
10 data/inflammation-11.csv
11 data/inflammation-12.csv
12 data/small-01.csv
13 data/small-02.csv
14 data/small-03.csv<jupyter_text>Conditionals<jupyter_code>num = 100
print('num is ', num)
if num > 100:
    print('greater')
elif num == 100:
    print('equals 100')
else:
    print('not greater')
print('done')
print(num > 100)
print(num == 100)
if (1 > 0) and (-1 > 0):
    print ('both parts are true')
else:
    print('at least one part is false')
if (1 > 0) or (-1 > 0):
    print ('at least one part is true')
else:
    print('Both parts are false')<jupyter_output>at least one part is true<jupyter_text>If using bitwise and and or (&, |) need parenthases Function<jupyter_code>def fahr_to_kelvin(temp_f):
    '''
    Converts fahrinheit to kelvin
    Input:
        temp_f: temperature in units of fahrinheit
    Output:
        temp in units of kelvin
    '''
    temp_k = ((temp_f - 32) * (5./9))-273.15
    return temp_k

def kelvin_to_celsius(temp_k):
    temp_c = temp_k + 273.15
    return temp_c

def fahr_to_celsius(temp_f):
    temp_k = fahr_to_kelvin(temp_f)
    temp_c = kelvin_to_celsius(temp_k)
    return temp_c
fahr_to_celsius(32)
fahr_to_celsius(212.)
print(5//9)
print(5/9)
#In python 2: from future import division
def b():
    a()
def a():
    pass<jupyter_output><empty_output><jupyter_text>Exercise:Write the function make_plot so that the code below runs filenames = ...for ifile in filenames[0:3]:    make_plot(ifile)<jupyter_code>def make_plot(filename):
    '''
    Blah
    '''
    data = np.loadtxt(fname = filename, delimiter = ',')
    fig = matplotlib.pyplot.figure(figsize = (10.0, 3.0))
    
    mean_axis = fig.add_subplot(1, 3, 1)
    max_axis = fig.add_subplot(1, 3, 2)
    min_axis = fig.add_subplot(1, 3, 3)

    mean_axis.plot(data.mean(axis = 0))
    max_axis.plot(data.max(axis = 0))
    min_axis.plot(data.min(axis = 0))

    mean_axis.set_ylabel('Mean')
    mean_axis.set_xlabel('Day')

    max_axis.set_ylabel('Max')
    max_axis.set_xlabel('Day')

    min_axis.set_ylabel('Min')
    min_axis.set_xlabel('Day')

    fig.tight_layout()
    plt.show()
    
help(make_plot)
filenames = glob.glob('data/*csv')
for ifile in filenames[0:3]:
    make_plot(ifile)
help(fahr_to_kelvin)<jupyter_output>Help on function fahr_to_kelvin in module __main__:

fahr_to_kelvin(temp_f)
    Converts fahrinheit to kelvin
    Input:
        temp_f: temperature in units of fahrinheit
    Output:
        temp in units of kelvin<jupyter_text>Keywords<jupyter_code>def display(a = 1, b = 2, c = 3):
    print('a:', a, 'b:', b, 'c:', c)
display()
display(4)
display(4, 7)
display(4, 6, 9)
display(c = 10)
numpy.loadtxt('data/inflammation-01.csv', delimiter =  ',')
numpy.loadtxt?<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1543632515872028, 'fraction_numerical': 0.043196813145773685, 'mean_word_length': 4.929151291512915, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '212584', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 3541, 'n_tokens_neox': 3281, 'n_words': 651, 'path': 'python/inclass_az.ipynb', 'repo_name': 'abostroem/2016-01-03-aas', 'size': '8033'}