Retrieve the column labels/keys from any DataFrame or QuerySet-like table object

    >>> from collections import OrderedDict
    >>> get_column_labels(OrderedDict(zip('ABC', pd.np.arange(12).reshape((3,4)))))
    ['A', 'B', 'C']

def get_column_labels(obj):
    """Retrieve the column labels/keys from any DataFrame or QuerySet-like table object

    >>> from collections import OrderedDict
    >>> get_column_labels(OrderedDict(zip('ABC', pd.np.arange(12).reshape((3,4)))))
    ['A', 'B', 'C']
    """
    if not isinstance(obj, (list, tuple, pd.np.ndarray)):
        try:
            labels = [f.name for f in obj.model._meta.fields]
        except:
            try:
                labels = obj.keys()
            except:
                try:
                    labels = dir(obj)
                except:
                    labels = None
    elif all(isinstance(heading, basestring) for heading in obj[0]):
        labels = list(obj[0])
        # if obj isn't a reference to a mutable (dict, DataFrame, list, etc), this won't work
        del obj[0]
    return labels