Source

ml4hackers / ufo.py

Full commit
#!/usr/bin/env python

import pandas as pd
from datetime import date

columns = [
    "sighted_at",
    "reported_at",
    "location",
    "shape",
    "duration",
    "description",
]

def asdate(n):
    if int(n) == 0:
        return None

    year, month, day = int(n[:4]), int(n[4:6]), int(n[6:])
    month = month or 1
    day = day or 1

    return date(year, month, day)


df = pd.read_csv(
    open('ufo_fixed.tsv'),
    sep='\t',
    names=columns,
    converters = {
        'sighted_at': asdate,
        'reported_at': asdate,
    },
)