<jupyter_start><jupyter_text>Loops<jupyter_code>word = 'notebook'
print (word[4])
for char in word: 
    print (char)<jupyter_output>n
o
t
e
b
o
o
k<jupyter_text>Get a list of all the filenames from disk<jupyter_code>import glob
print (glob.glob('data/weather*.csv'))<jupyter_output>['data\\weather-01.csv', 'data\\weather-02.csv', 'data\\weather-03.csv', 'data\\weather-04.csv', 'data\\weather-05.csv', 'data\\weather-06.csv', 'data\\weather-07.csv', 'data\\weather-08.csv', 'data\\weather-09.csv', 'data\\weather-10.csv', 'data\\weather-11.csv', 'data\\weather-12.csv']<jupyter_text>Putting it all together<jupyter_code>filenames = sorted(glob.glob('data/weather*.csv'))
filenames = filenames[0:12]

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 ("Suspicous looking maximum")
    elif numpy.sum(numpy.min(data, axis=0)) == 0:
        print ("Minimum add up to zero")
    else:
        print ("Data looks OK")

    # Create a wide figure to hold the 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('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<jupyter_output>data\weather-01.csv
Suspicous looking maximum
data\weather-02.csv
Suspicous looking maximum
data\weather-03.csv
Minimum add up to zero
data\weather-04.csv
Suspicous looking maximum
data\weather-05.csv
Suspicous looking maximum
data\weather-06.csv
Suspicous looking maximum
data\weather-07.csv
Suspicous looking maximum
data\weather-08.csv
Minimum add up to zero
data\weather-09.csv
Suspicous looking maximum
data\weather-10.csv
Suspicous looking maximum
data\weather-11.csv
Minimum add up to zero
data\weather-12.csv
Suspicous looking maximum<jupyter_text>Making decisions<jupyter_code>num = 107
if num > 100: 
    print ('Greater')
else:
    print ('Not greater')
    print ('Done')    
num = 6
if num > 0:
    print (num, "is positive")
elif num == 0:
    print (num, "is zero")
else:
    print (num, "is negative")<jupyter_output>6 is positive<jupyter_text>Functions<jupyter_code>def fahr_to_kelvin(temp):
    return ((temp - 32) * (5/9) + 273.15)
print ('Freezing point of water: ', fahr_to_kelvin(32))
print ('Boiling point of water: ', fahr_to_kelvin(212))
def analyse (filename):
    data = numpy.loadtxt(fname=filename, delimiter=',')
    
    """This function analyses the temperature data and plots it into three separate subplots which contain the average
    maximum and minimum temperature data, respectively"""
    
    # Create a wide figure to hold the 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('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
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] == 0 and numpy.max (data, axis=0)[20] ==20:
        print ("Suspicous looking maximum")
    elif numpy.sum(numpy.min(data, axis=0)) == 0:
        print ("Minimum add up to zero")
    else:
        print ("Data looks OK")
for f in filenames [0:5]:
    print (f)
    analyse (f)
    detect_problems (f)
help(numpy.loadtxt)
help(detect_problems)
help(detect_problems)

help(detect_problems)
help(analyse)
help(analyse)<jupyter_output>Help on function analyse in module __main__:

analyse(filename)
{'fraction_non_alphanumeric': 0.13108784706417842, 'fraction_numerical': 0.03413746017296313, 'mean_word_length': 3.8779134295227524, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '49790', 'license': 'MIT', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1561, 'n_words': 395, 'path': '02-plots-and-subplots.ipynb', 'repo_name': 'adwood92/sc-python-bristol', 'size': '4394'}