In [1]:
import numpy
import matplotlib.pyplot
%matplotlib inline
In [2]:
data = numpy.loadtxt (fname = 'data/weather-01 csv' , delimiter = ',')
In [3]:
data = numpy.loadtxt (fname = 'data/weather-01.csv' , delimiter = ',')
In [4]:
print (data)
In [5]:
#Create a wide figure to hold subplots
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('minimum')
subplot2.plot(numpy.min(data, axis=0))
subplot3.set_ylabel('maximum')
subplot3.plot(numpy.max(data, axis=0))
fig.tight_layout()
matplotlib.pyplot.show()
In [6]:
#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('minimum')
subplot2.plot(numpy.min(data, axis=0))
subplot3.set_ylabel('maximum')
subplot3.plot(numpy.max(data, axis=0))
fig.tight_layout()
matplotlib.pyplot.show()
In [7]:
subplot1.set_ylabel('average')
subplot1.plot(numpy.mean(data, axis=0))
subplot2.set_ylabel('minimum')
subplot2.plot(numpy.min(data, axis=0))
subplot3.set_ylabel('maximum')
subplot3.plot(numpy.max(data, axis=0))
fig.tight_layout()
matplotlib.pyplot.show()
In [8]:
word = 'notebook'
print (word[4])
In [9]:
for char in word:
print (char)
In [10]:
import glob
In [11]:
print(glob.glob('data/weather*.csv'))
In [12]:
filenames = sorted(glob.glob('data/weather*.csv'))
#just data01, data02 and data03 from the list on the top:
filenames = filenames[0:3]
for f in filenames:
print (f)
data = numpy.loadtxt(fname=f, delimiter=',')
#Create a wide figure to hold subplots
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('minimum')
subplot2.plot(numpy.min(data, axis=0))
subplot3.set_ylabel('maximum')
subplot3.plot(numpy.max(data, axis=0))
fig.tight_layout()
matplotlib.pyplot.show()
In [13]:
num =107
if num > 100:
print ('Greater')
else:
print ('Not greater')
print ('Done')
num =107 if num > 100: print ('Greater') else: print ('Not greater')
print ('Done')
In [14]:
num = -3
if num > 0:
print (num, "is positive")
elif num ==0:
print (num, "is zero")
else:
print (num, "is negative")
In [15]:
num = 0
if num > 0:
print (num, "is positive")
elif num ==0:
print (num, "is zero")
else:
print (num, "is negative")
In [16]:
num = 5
if num > 0:
print (num, "is positive")
elif num ==0:
print (num, "is zero")
else:
print (num, "is negative")
In [17]:
filenames = sorted(glob.glob('data/weather*.csv'))
#just data01, data02 and data03 from the list on the top:
filenames = filenames[0:3]
for f in filenames:
print (f)
data = numpy.loadtxt(fname=f, delimiter=',')
if numpy.max (data, axis=0)[0] == 0 and numpy.max (data, axis=0)[20] ==20:
print ("Suspicious looking maxima")
elif numpy.sum(numpy.min(data, axis=0)) == 0:
print ("Minima add up to zero")
else:
print ("Data looks OK")
#Create a wide figure to hold subplots
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('minimum')
subplot2.plot(numpy.min(data, axis=0))
subplot3.set_ylabel('maximum')
subplot3.plot(numpy.max(data, axis=0))
fig.tight_layout()
matplotlib.pyplot.show()
In [18]:
filenames = sorted(glob.glob('data/weather*.csv'))
#just data01, data02 and data03 from the list on the top:
#filenames = filenames[0:3]
for f in filenames:
print (f)
data = numpy.loadtxt(fname=f, delimiter=',')
if numpy.max (data, axis=0)[0] == 0 and numpy.max (data, axis=0)[20] ==20:
print ("Suspicious looking maxima")
elif numpy.sum(numpy.min(data, axis=0)) == 0:
print ("Minima add up to zero")
else:
print ("Data looks OK")
#Create a wide figure to hold subplots
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('minimum')
subplot2.plot(numpy.min(data, axis=0))
subplot3.set_ylabel('maximum')
subplot3.plot(numpy.max(data, axis=0))
fig.tight_layout()
matplotlib.pyplot.show()
In [ ]:
def fahr_to_kelvin(temp):
return((temp - 32)*(5/9)+273.15)
In [ ]:
print('Freezing point of water: ', fahr_to_kelvin(32))
In [ ]:
print('Boiling point of water: ', fahr_to_kelvin(212))
In [19]:
def analyse (filename):
data = numpy.loadtxt(fname=filename, delimiter=',')
#Create a wide figure to hold subplots
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('minimum')
subplot2.plot(numpy.min(data, axis=0))
subplot3.set_ylabel('maximum')
subplot3.plot(numpy.max(data, axis=0))
fig.tight_layout()
matplotlib.pyplot.show()
In [29]:
def detect_problems (filename):
"""Some of our temperature files have problems, check for these
This functions 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] == 0 and numpy.max (data, axis=0)[20] ==20:
print ("Suspicious looking maxima")
elif numpy.sum(numpy.min(data, axis=0)) == 0:
print ("Minima add up to zero")
else:
print ("Data looks OK")
In [21]:
for f in filenames [0:5]:
print (f)
analyse (f)
detect_problems (f)
In [22]:
help(numpy.load.txt)
In [23]:
help(numpy.loadtxt)
In [27]:
help(detect_problems)
In [30]:
help(detect_problems)
In [ ]: