In [1]:
from pylab import *
import pandas as pd
from IPython.core.display import HTML
from matplotlib.dates import MonthLocator,DateFormatter
import urllib
In [2]:
# full path name of spreadsheet file from Coalition for Buzzards Bay
xls_file = pd.ExcelFile('/usgs/data2/notebook/Falmouth_data.xlsx')
In [4]:
# parse data, replacing all the entries in the na_values list below with NaN, and also converting <0.1 to 0.1
# I can't get this to work. It runs without error, but I still have <0.1 in my data.
asn = xls_file.parse('all stations, raw nutrients',index_col='Date',
na_values=['?',None,'No Sample','NS','NES','no sample left','Sample Destroyed','machine error','#VALUE!'])
In [5]:
def convert_detection_limit(a,var,lim,val):
try:
a[var][where(a[var]==lim)[0]] = val
except:
print 'No detection values found for %s' % var
return a
In [6]:
asn=convert_detection_limit(asn,'PO4 uM','<0.1',0.05)
asn=convert_detection_limit(asn,'NH4 uM','<0.1',0.05)
asn=convert_detection_limit(asn,'NO3 uM','<0.05',0.025)
asn=convert_detection_limit(asn,'Pheo ug/L','<0.05',0.025)
In [7]:
sta = {
'PO4 uM': ('<0.1',0.05),
'NH4 uM': ('<0.1',0.05),
'Pheo': ('<0.05',0.025),
'NO3 uM': ('<0.05',0.025)
}
In [8]:
#find all the data at station
qh2=asn[asn['Station']=='QH2'] #quissett harbor, qh2
mg4=asn[asn['Station']=='MG4'] #megansett harbor, mg4
In [9]:
#plot up POM
qh2['POM uM'].plot(figsize(16,4),linestyle='None',marker='o',legend='best')
Out[9]:
In [10]:
# print just a few columns and render as HTML
new=mg4.reindex(columns=['Embayment','Station','Depth (m)','Temp C','Salt ppt',
'PO4 uM','POM uM','NH4 uM','NO3 uM','TDN uM','Pheo ug/L'])
HTML(new.to_html())
Out[10]:
In [11]:
#try to make stacked plots, one for each year
# I'm sure this isn't the best way
figure(figsize(16,8))
fix, axes = subplots(5,1,sharex=False, sharey=True)
starty=1995
mthFmt = DateFormatter('%b')
months = MonthLocator()
for j in range(5):
start='%4.4d' % (starty + j)
stop = '%4.4d' % (starty + j + 1)
qh2['POM uM'][start:stop].plot(ax=axes[j],linestyle='None',marker='o',xlim=[start,stop],label=start)
axes[j].xaxis.set_major_locator(months)
axes[j].xaxis.set_major_formatter(mthFmt)
axes[j].legend(loc='upper left')
In [14]:
# all west falmouth data
wf =asn[asn['Station'].isin(['WF5','WF5pw'])]
In [21]:
wf['PO4 uM'].plot(linestyle='None',marker='o',legend='best')
Out[21]:
In [42]:
money_conversion = '%.2f Argentine Pesos are worth $%d'
money_conversion % (4.5560, 1)
Out[42]:
In [4]:
def attempt_float(x):
try:
return float(x)
except ValueError:
return x
In [6]:
attempt_float((1,2))
In [40]:
sum = 0
for i in xrange(1000):
if i % 3 == 0 or i % 5 == 0:
sum += i
print sum