We are going to use a LIBRARY called numpy
In [1]:
import numpy
In [2]:
numpy.loadtxt(fname = 'data/weather-01.csv',delimiter = ',')
Out[2]:
In [3]:
weight_kg = 55
In [4]:
print (weight_kg)
In [5]:
print ('Weight in pounds:', weight_kg * 2.2)
In [6]:
weight_kg = 57.5
In [7]:
print ('New Weight: ',weight_kg*2.2)
In [8]:
%whos
In [9]:
data = numpy.loadtxt(fname = 'data/weather-01.csv',delimiter = ',')
In [10]:
print (data)
In [12]:
print(type(data))
In [13]:
%whos
In [14]:
# Finding out the data type
print (data.dtype)
In [15]:
# Find out the shape
print(data.shape)
In [16]:
# This is 60 rows by 40 columns
In [17]:
# getting a single number out of the array
print ("First value in data: ", data [0, 0])
In [18]:
print ('a middle value: ', data[30, 20])
In [19]:
# Lets get the first 10 columns for the first 4 rows
print (data[0:4,0:10])
# index says start at 0 and go up to but dont include 4
In [20]:
# we dont need to start sices at zero
print (data [5:10,7:15])
In [21]:
# we dont even need to include the UPPER and LOWER bounds
smallchunk = data [:3,36:]
print(smallchunk)
In [22]:
# aritmetic on arrays
doublesmallchunk = smallchunk * 2.0
In [23]:
print(doublesmallchunk)
In [24]:
triplesmallchunk = smallchunk + doublesmallchunk
In [25]:
print(triplesmallchunk)
In [26]:
print(numpy.mean(data))
In [27]:
print(numpy.mean(triplesmallchunk))
In [28]:
print(numpy.max(data))
In [29]:
print(numpy.min(data))
In [30]:
# get a set of data from the first station
station_0 = data [0, :]
In [31]:
print (numpy.max(station_0))
In [32]:
# We dont need to create 'temporary' array slices
# We can refer to what we call array axes
In [35]:
# axis = 0 gets the mean down each column , so the mean
# temperature for each recording period
print(numpy.mean(data, axis = 0))
In [36]:
# axis = 0 gets the mean across each column , so the mean
# temperature for each station for all periods
print(numpy.mean(data, axis =1))
In [37]:
# Do some simple visulisations
In [38]:
import matplotlib.pyplot
In [39]:
%matplotlib inline
In [40]:
image = matplotlib.pyplot.imshow(data)
In [41]:
# let's look at the average temperature over time
avg_temperature = numpy.mean(data,axis =0)
In [42]:
avg_plot = matplotlib.pyplot.plot(avg_temperature)
In [43]:
min_temperature = numpy.min(data,axis = 0)
max_temperature = numpy.max(data,axis = 0)
In [44]:
min_plot = matplotlib.pyplot.plot(min_temperature)
In [45]:
max_plot = matplotlib.pyplot.plot(max_temperature)
In [46]:
avg_plot = matplotlib.pyplot.plot(avg_temperature)
max_plot = matplotlib.pyplot.plot(max_temperature)
min_plot = matplotlib.pyplot.plot(min_temperature)
In [ ]: