In [2]:
import numpy
import matplotlib.pyplot
%matplotlib inline

In [3]:
data = numpy.loadtxt(fname = 'data/weather-01.csv',delimiter = ',')


---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-3-29d7a53f9fe1> in <module>()
----> 1 data = numpy.loadtxt(fname = 'data/weather-01.csv',delimiter = ',')

C:\Users\censah.cencom990\Anaconda3\lib\site-packages\numpy\lib\npyio.py in loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin)
    803                 fh = iter(open(fname, 'U'))
    804             else:
--> 805                 fh = iter(open(fname))
    806         else:
    807             fh = iter(fname)

FileNotFoundError: [Errno 2] No such file or directory: 'data/weather-01.csv'

In [4]:
data = numpy.loadtxt(fname = 'data/data/weather-01.csv',delimiter = ',')

In [5]:
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)


<matplotlib.figure.Figure at 0x4e0eef0>

In [6]:


In [15]:
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('max')
subplot1.plot(numpy.max(data, axis=0))

subplot2.set_ylabel('average')
subplot2.plot(numpy.mean(data, axis=0))

subplot3.set_ylabel('min')
subplot3.plot(numpy.min(data, axis=0))

fig.tight_layout()
matplotlib.pyplot.show()



In [16]:
word = 'notebook'
print (word[4])


b

In [17]:
for char in word:
    print (char)


n
o
t
e
b
o
o
k

In [18]:
# Get a list of all the filenames from disk

In [19]:
import glob

In [21]:
print (glob.glob('data/weather*.csv'))


[]

In [22]:
print (glob.glob('data/data/weather*.csv'))


['data/data\\weather-01.csv', 'data/data\\weather-02.csv', 'data/data\\weather-03.csv', 'data/data\\weather-04.csv', 'data/data\\weather-05.csv', 'data/data\\weather-06.csv', 'data/data\\weather-07.csv', 'data/data\\weather-08.csv', 'data/data\\weather-09.csv', 'data/data\\weather-10.csv', 'data/data\\weather-11.csv', 'data/data\\weather-12.csv']

In [34]:
filenames = sorted(glob.glob('data/weather*.csv'))



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('max')
subplot1.plot(numpy.max(data, axis=0))

subplot2.set_ylabel('average')
subplot2.plot(numpy.mean(data, axis=0))

subplot3.set_ylabel('min')
subplot3.plot(numpy.min(data, axis=0))

fig.tight_layout()
matplotlib.pyplot.show()



In [35]:
filenames = sorted(glob.glob('data/data/weather*.csv'))
#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")
        

    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('max')
    subplot1.plot(numpy.max(data, axis=0))

    subplot2.set_ylabel('average')
    subplot2.plot(numpy.mean(data, axis=0))

    subplot3.set_ylabel('min')
    subplot3.plot(numpy.min(data, axis=0))

    fig.tight_layout()
    matplotlib.pyplot.show()


data/data\weather-01.csv
Suspicious looking maxima
data/data\weather-02.csv
Suspicious looking maxima
data/data\weather-03.csv
Minima add up to zero
data/data\weather-04.csv
Suspicious looking maxima
data/data\weather-05.csv
Suspicious looking maxima
data/data\weather-06.csv
Suspicious looking maxima
data/data\weather-07.csv
Suspicious looking maxima
data/data\weather-08.csv
Minima add up to zero
data/data\weather-09.csv
Suspicious looking maxima
data/data\weather-10.csv
Suspicious looking maxima
data/data\weather-11.csv
Minima add up to zero
data/data\weather-12.csv
Suspicious looking maxima

Making decisions


In [28]:
num = 37
if num > 100:
    print ('Greater')
else:
    print ('Not greater')
    
print ('Done')


Not greater
Done

In [32]:
num = 0

if num > 0:
    print (num, "is positive")
elif num == 0:
    print (num, "is zero")
else:
    print (num, "is negative")


0 is zero

Functions


In [36]:
def fahr_to_kelvin(temp):
    return((temp-32)*(5/9)+273.15)

In [37]:
print ('Freezing point of water: ', fahr_to_kelvin(32))


Freezing point of water:  273.15

In [38]:
print ('Freezing point of water: ', fahr_to_kelvin(212))


Freezing point of water:  373.15

In [42]:
def analyse (filename):
    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")
        

    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('max')
    subplot1.plot(numpy.max(data, axis=0))

    subplot2.set_ylabel('average')
    subplot2.plot(numpy.mean(data, axis=0))

    subplot3.set_ylabel('min')
    subplot3.plot(numpy.min(data, axis=0))

    fig.tight_layout()
    matplotlib.pyplot.show()

In [1]:
def detect_problems (filename):
    """
    This is to detect problem in the 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 [45]:
for f in filenames [0:5]:
    print (f)
    analyse (f)
    detect_problems (f)


data/data\weather-01.csv
Suspicious looking maxima
Suspicious looking maxima
data/data\weather-02.csv
Suspicious looking maxima
Suspicious looking maxima
data/data\weather-03.csv
Minima add up to zero
Minima add up to zero
data/data\weather-04.csv
Suspicious looking maxima
Suspicious looking maxima
data/data\weather-05.csv
Suspicious looking maxima
Suspicious looking maxima

In [2]:
help(detect_problems)


Help on function detect_problems in module __main__:

detect_problems(filename)
    This is to detect problem in the data


In [ ]: