We are going to use a LIBRARY called numpy
In [16]:
import numpy
In [17]:
numpy.loadtxt(fname='data/weather-01.csv', delimiter = ',')
Out[17]:
In [18]:
weight_kg = 55
In [19]:
print (weight_kg)
In [20]:
print ('Weight in pounds: ', weight_kg *2.2)
In [21]:
weight_kg = 57.5
In [22]:
print ('Weight in pounds: ', weight_kg *2.2)
In [23]:
%whos
In [24]:
data = numpy.loadtxt(fname='data/weather-01.csv', delimiter = ',')
In [25]:
print (data)
In [26]:
print(type(data))
In [27]:
%whos
In [28]:
# Finding out the data type
print (data.dtype)
In [29]:
# Finding out the shape
print (data.shape)
In [30]:
# This is 60 rows * 40 columns
In [31]:
# Getting a number out of the array
print ("First value in data: ", data [0,0])
In [32]:
print ("A value from a selected row and column position: ", data[30,20])
In [33]:
#Lets get the first 10 columns for the first 4 rows
# notation means start at X and go up to but not including Y [X:Y]
print (data[0:4, 0:10])
In [34]:
# can start slicing anywhere
print (data[3:8, 4:7])
In [35]:
#Don't need to include the upper and lower bounds, uses 0 instead or end
smallchunk= data[:3,36:]
print(smallchunk)
In [36]:
# Arithmetic with arrays
doublesmallchunk = smallchunk *2.0
In [37]:
print(doublesmallchunk)
In [38]:
triplesmallchunk = smallchunk+doublesmallchunk
In [39]:
print(triplesmallchunk)
In [40]:
print(numpy.mean(data))
In [41]:
print(numpy.max(data))
In [42]:
print(numpy.min(data))
In [43]:
# Get a set of data for the first station
station_0 = data[0, :]
In [44]:
print (numpy.max(station_0))
In [45]:
# We don't need to creat these 'temporary' array slices
# We can refer to what we call array axes
In [46]:
print(numpy.mean(data, axis = 0))
In [47]:
print(numpy.mean(data, axis = 1))
In [48]:
# axis = 0 means calculate down each column (i.e. mean of the values in a column)
# axis = 1 means calculate mean across the rows (i.e. mean of the values in a row)
In [49]:
import matplotlib.pyplot
In [50]:
%matplotlib inline
In [51]:
image = matplotlib.pyplot.imshow(data)
In [52]:
# Let's look at the average temperature over time
avg_temperature = numpy.mean(data, axis = 0)
In [53]:
avg_plot = matplotlib.pyplot.plot (avg_temperature)
In [54]:
# Plot min temperature over time
min_temperature = numpy.min(data, axis=0)
min_plot = matplotlib.pyplot.plot(min_temperature)
In [55]:
# plot max temperautres
max_temperature = numpy.max(data, axis =0)
max_plot = matplotlib.pyplot.plot(max_temperature)
In [ ]:
In [ ]: