Monthly Archives: November 2014

Dates and Times in Python: average of two dates with Pandas

I spent a little longer than expected figuring out how to find the midpoint of two dates for a little table of data recently. Here is a code snippet in case I (or you) have to do this again:

# midpoint of two date columns
df = pd.DataFrame({'a': ['5/1/2012 0:00', '4/1/2014 0:00'],
                   'b': ['4/1/2014 0:00', 'unknown']})

# make time data into Timestamp format
def try_totime(t):
    try:
        return pd.Timestamp(t)
    except:
        return np.nan
    
df['start'] = df.a.map(try_totime)
df['end'] = df.b.map(try_totime)

# generate midpoint time
# harder than it would seem...
df['time'] = df.start + (df.end - df.start)/2

df

2 Comments

Filed under software engineering

What I’m Reading: The Design and Implementation of Probabilistic Programming Languages

A new online book crossed my screen recently: The Design and Implementation of Probabilistic Programming Languages. Looks good so far.

Comments Off on What I’m Reading: The Design and Implementation of Probabilistic Programming Languages

Filed under Uncategorized

Research Culture Questionnaire

Interesting questionnaire on research culture from CACM (article | questions) . Would be fun to have a school of public health version…

Comments Off on Research Culture Questionnaire

Filed under science policy

My Coursera Obsession: Visual Perception and the Brain

Did I already mention this MOOC watching habit I developed over the summer? I got sucked in to watching lectures online from all sort of classes. It is sort of like being in college again, but when I fall asleep during lecture, I can rewind when I wake up (if I want to).

One of the classes that I devoured video lectures from is , taught by Duke neuroscience prof Dale Purves. It’s got a little bit of that evolutionary-psychologist-explains-everything flavor, and a lot of visual illusions to use-not-abuse in data visualizations.

I remembered it when watching animal videos with my two year old today (his choice). Here is something that 75 million years of primate evolution can do, and it needs quite the visual system to do so: http://www.arkive.org/verreauxs-sifaka/propithecus-verreauxi/video-06a.html

2 Comments

Filed under education