Script to extract ferret timeseries data into two columns of numbers. Handles files with and without dates for x-values
In [1]:
    
import pandas as pd
# For bokeh plots
import bokeh #0.12.3
from bokeh.plotting import figure
from datetime import datetime as dt
from bokeh.models import DatetimeTickFormatter
from math import pi
    
In [3]:
    
# Read csv file output by ferret
df_orig = pd.read_csv('levitus.csv', delimiter=':', index_col=0)
df_orig.head(10)
    
    Out[3]:
In [31]:
    
# Read csv file output by ferret, skipping header
df = pd.read_csv('levitus.csv', delimiter=':', skiprows=5)
df.head(5)
    
    Out[31]:
In [32]:
    
#Extract date string from col 0
s = df.ix[:, 0]
s.head(5)
    
    Out[32]:
In [33]:
    
x = s.str.split(' /').str.get(0).str.split(' ').str.get(1)
x.head(5)
    
    Out[33]:
In [34]:
    
# Determine if x-col is a list of dates
months=['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
dateFlag=0
for idx in range(12):
    if x[0].find(months[idx]) != -1:
        print("found month")
        dateFlag=1
print dateFlag
    
    
In [35]:
    
if dateFlag==1:
    x = pd.to_datetime(x,infer_datetime_format=True)
x.head(5)
    
    Out[35]:
In [36]:
    
# Put x and y values in dataframe
dfer = pd.DataFrame()
dfer['xval'] = x
dfer['yval'] = df.ix[:, 1]
dfer.head(5)
    
    Out[36]:
In [37]:
    
p = figure(title='A Bokeh plot',
        plot_width=700,plot_height=400)
    
In [38]:
    
p.line(dfer['xval'], dfer['yval'])
    
    Out[38]:
In [39]:
    
if dateFlag==1:
    p.xaxis.formatter=DatetimeTickFormatter(formats=dict(
        hours=["%d %B %Y"],
        days=["%d %B %Y"],
        months=["%d %B %Y"],
        years=["%d %B %Y"],
    ))
p.xaxis.major_label_orientation = pi/4
p.yaxis.axis_label = "size"
    
In [40]:
    
# For plotting in notebook
from bokeh.io import output_file
from bokeh.charts import show
from bokeh.models import DatetimeTickFormatter
output_file('myplot2.html')
show(p)
    
In [ ]:
    
    
In [ ]: