Analaysing Tabular Data
We are going to use a LIBRARY called numpy
In [84]:
    
import numpy
    
In [85]:
    
numpy.loadtxt(fname='data/weather-01.csv', delimiter = ',')
    
    Out[85]:
Variables
In [86]:
    
weight_kg = 55
    
In [87]:
    
print (weight_kg)
    
    
In [88]:
    
print ('Weight in pounds:', weight_kg * 2.2)
    
    
In [89]:
    
weight_kg = 57.5
    
In [90]:
    
print ('New weight:', weight_kg * 2.2)
    
    
In [91]:
    
%whos
    
    
In [92]:
    
data = numpy.loadtxt(fname='data/weather-01.csv', delimiter = ',')
    
In [93]:
    
print (data)
    
    
In [94]:
    
print (type (data))
    
    
In [95]:
    
%whos
    
    
In [96]:
    
# Finding out the data type
print (data.dtype)
    
    
In [97]:
    
# Find out the shape
print (data.shape)
    
    
In [98]:
    
# This is 60 rows * 40 columns
    
In [99]:
    
# Getting a single mmuber out of the array
print ("First value in data:", data [0,0])
    
    
In [100]:
    
print ('A mimddle value:', data [30,20])
    
    
In [101]:
    
# Lets get the first 10 columns for the first 4 rows
print (data [0:4,0:10])
# Start at index 0 and go up to But Not including index 4
    
    
In [102]:
    
# We don't need to start slicing at 0
print (data [5:10, 7:15])
    
    
In [103]:
    
# We don't need to include Upper and Lower bounds
smallchunk = data [:3, 36:]
print (smallchunk)
    
    
In [104]:
    
# Arithmetic on Arrays
doublesmallchunk = smallchunk * 2.0
    
In [105]:
    
print (doublesmallchunk)
    
    
In [106]:
    
triplesmallchunk = smallchunk + doublesmallchunk
    
In [107]:
    
print (triplesmallchunk)
    
    
In [108]:
    
print (numpy.mean(data))
    
    
In [109]:
    
print (numpy.max(data))
    
    
In [110]:
    
print (numpy.min(data))
    
    
In [111]:
    
# Get a set of data for the first station
station_0 = data [0, :]
    
In [112]:
    
print (numpy.max(station_0))
    
    
In [113]:
    
# We dont need to create this 'temporary' array slices
# We can refer to what we call array axes
    
In [114]:
    
# axis = 0 gets the mean Down the column, so the mean tempreature 
# for each recording period
print (numpy.mean(data, axis = 0))
    
    
In [115]:
    
# axis = 1 gets the mean across the row, so the mean tempreature 
# for each recording period
print (numpy.mean(data, axis = 1))
    
    
In [116]:
    
# Do some simple Visulaisations
    
In [117]:
    
import matplotlib.pyplot
    
In [118]:
    
%matplotlib inline
    
In [119]:
    
image = matplotlib.pyplot.imshow(data)
    
    
In [120]:
    
%whos
    
    
In [121]:
    
# Let's look at the average tempreture over time
avg_temperature = numpy.mean(data, axis = 0)
    
In [122]:
    
avg_plot = matplotlib.pyplot.plot(avg_temperature)
    
    
In [123]:
    
# Task: 
# Produce maximum and minimum plots of this data
# What do you think
    
In [124]:
    
avg_temperature_max = numpy.max(data, axis = 0)
    
In [125]:
    
avg_plot_max = matplotlib.pyplot.plot(avg_temperature_max)
    
    
In [126]:
    
avg_temperature_min = numpy.min(data, axis = 0)
    
In [128]:
    
avg_plot_min = matplotlib.pyplot.plot(avg_temperature_min)
    
    
In [130]:
    
avg_combine_plot = matplotlib.pyplot.plot(avg_temperature_min, avg_temperature_max)
    
    
In [ ]: