In [1]:
import numpy
import matplotlib.pyplot
%matplotlib inline
In [2]:
data = numpy.loadtxt (fname = 'data/weather-01.csv', delimiter =',')
In [3]:
fig = matplotlib.pyplot.figure (figsize= (10.0, 3.0))
# create placeholders for plots
subplot1 = fig.add_subplot (1, 3, 1)
subplot2 = fig.add_subplot (1, 3, 2)
subplot3 = fig.add_subplot (1, 3, 3)
subplot1.set_ylabel('average')
subplot1.plot(numpy.mean(data, axis = 0))
subplot2.set_ylabel('max')
subplot2.plot(numpy.max(data, axis = 0))
subplot3.set_ylabel('min')
subplot3.plot(numpy.min(data, axis = 0))
fig.tight_layout()
matplotlib.pyplot.show
Out[3]:
In [4]:
word = 'notebook'
In [5]:
print(word[4])
In [6]:
for char in word:
print(char)
In [7]:
import glob
In [8]:
print (glob.glob('data/weather*.csv')) # generates a list, single dimension container for data
In [9]:
filenames = sorted(glob.glob('data/weather*.csv')) # sorted gets data sets in right order
#filenames = filenames[0:3]
for f in filenames:
print (f)
data = numpy.loadtxt(fname=f, delimiter =',')
if numpy.max (data, axis = 0)[0] and numpy.max(data, axis = 0)[20] ==20:
print ("Suspicious looking maximum")
elif numpy.sum(numpy.min(data, axis = 0)) ==0:
print ("Minima to zero")
else:
print ("Data looks OK")
fig = matplotlib.pyplot.figure (figsize= (10.0, 3.0))
subplot1 = fig.add_subplot (1, 3, 1)
subplot2 = fig.add_subplot (1, 3, 2)
subplot3 = fig.add_subplot (1, 3, 3)
subplot1.set_ylabel('average')
subplot1.plot(numpy.mean(data, axis = 0))
subplot2.set_ylabel('max')
subplot2.plot(numpy.max(data, axis = 0))
subplot3.set_ylabel('min')
subplot3.plot(numpy.min(data, axis = 0))
fig.tight_layout()
matplotlib.pyplot.show()
In [10]:
num = 107
if num > 100:
print("Greater")
print("Done")
else:
print ("Not greater")
print ("Done")
In [11]:
num = -3
if num > 0:
print(num, "is positive")
elif num == 0:
print (num, "is zero")
else:
print (num, "is negative")
In [12]:
num = 107 + 33 + 222
for inte in num:
if num > 100:
print("Greater")
print("Done")
else:
print ("Not greater")
print ("Done")
In [13]:
def fahr_to_kelvin(temp):
return ((temp - 32) * (5/9) + 273.15)
In [14]:
fahr_to_kelvin(44)
Out[14]:
In [15]:
print('Freezing point of water: ', fahr_to_kelvin(32))
In [16]:
print('Boiling point of water: ', fahr_to_kelvin(212))
In [35]:
def analyse (filename):
""" Displays the mean, maxima and minimum value for each weather station.
Creates a figure of three subplots, showing values for mean, maxima and minimum value with axis = 0,
y axis labels, and a tight layout.
"""
data = numpy.loadtxt(fname=filename, delimiter =',')
fig = matplotlib.pyplot.figure (figsize= (10.0, 3.0))
subplot1 = fig.add_subplot (1, 3, 1)
subplot2 = fig.add_subplot (1, 3, 2)
subplot3 = fig.add_subplot (1, 3, 3)
subplot1.set_ylabel('average')
subplot1.plot(numpy.mean(data, axis = 0))
subplot2.set_ylabel('max')
subplot2.plot(numpy.max(data, axis = 0))
subplot3.set_ylabel('min')
subplot3.plot(numpy.min(data, axis = 0))
fig.tight_layout()
matplotlib.pyplot.show()
In [36]:
def detect_problems (filename):
"""Some of our temperature files have problems, check for these
This function reads a file(filename argument) and reports on odd looking maxima,
and minima that add up to zero. This seems to happen when the sensors break.
The function does not return any data.
"""
data = numpy.loadtxt(fname=filename, delimiter =',')
if numpy.max (data, axis = 0)[0] and numpy.max(data, axis = 0)[20] ==20:
print ("Suspicious looking maximum")
elif numpy.sum(numpy.min(data, axis = 0)) ==0:
print ("Minima to zero")
else:
print ("Data looks OK")
In [26]:
for f in filenames [0:5]:
print(f)
analyse(f)
detect_problems(f)
In [31]:
# how to we write help documentation for our own functions?
help(detect_problems)
In [34]:
help(detect_problems)
In [37]:
help(analyse)
In [ ]:
In [ ]: