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]:
Variables
In [5]:
Weight_kg = 55
In [8]:
print (Weight_kg)
In [9]:
print('Weight in pounds:', Weight_kg * 2.2)
In [10]:
Weight_kg = 57.5
In [12]:
print ('New weight: ', Weight_kg * 2.2)
In [13]:
%whos
In [14]:
data = numpy.loadtxt(fname='data/weather-01.csv', delimiter = ',')
In [15]:
print (data)
In [16]:
print (type(data))
In [17]:
%whos
In [18]:
# Finding out the data type
print (data.dtype)
In [19]:
# Find out the shape
print (data.shape)
In [20]:
# This is 60 rows * 40 columns
In [22]:
# Getting a single number out of the array
print ("First value in data: ", data [0, 0])
In [24]:
print ('A middle value: ', data[30, 20])
In [26]:
# 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 [27]:
# We don't need to start slicing at 0
print (data [5:10, 7:15])
In [28]:
# We don't even need to include the UPPER and LOWER bounds
smallchunk = data [:3, 36:]
print (smallchunk)
In [29]:
# Arithmetic on arrays
doublesmallchunk = smallchunk * 2.0
In [30]:
print (doublesmallchunk)
In [31]:
triplesmallchunk = smallchunk + doublesmallchunk
In [32]:
print (triplesmallchunk)
In [33]:
print (numpy.mean(data))
In [34]:
print (numpy.transpose(data))
In [35]:
print (numpy.max(data))
In [36]:
print (numpy.min(data))
In [39]:
# Get a set of data for the first station
station_0 = data [0, :]
In [40]:
print (numpy.max(station_0))
In [41]:
# We don't need to create 'temporary' array slices
# We can refer to what we call array axes
In [47]:
# axis = 0 gets the mean DOWN each column, so the mean temperature for each recording period
print (numpy.mean(data, axis = 0))
In [48]:
# axis = 1 gets the mean ACROSS each row, so the mean temperature for each recording period
print (numpy.mean(data, axis = 1))
In [49]:
# do some simple visualisations
In [50]:
import matplotlib.pyplot
In [51]:
%matplotlib inline
In [52]:
image = matplotlib.pyplot.imshow(data)
In [53]:
# Let's look at the average temprature over time
avg_temperature = numpy.mean(data, axis = 0)
In [54]:
avg_plot = matplotlib.pyplot.plot(avg_temperature)
Tasks
In [59]:
max_temprature = numpy.max(data, axis = 0)
min_temprature = numpy.min(data, axis = 0)
max_plot = matplotlib.pyplot.plot(max_temprature)
min_plot = matplotlib.pyplot.plot(min_temprature)
In [58]:
min_p = numpy.min(data, axis = 0)
min_plot = matplotlib.pyplot.plot(min_p)
In [ ]: