def as_dict(df, ix=':'):
    """ converts df to dict and adds a datetime field if df is datetime """
    if isinstance(df.index, pd.DatetimeIndex):
        df['datetime'] = df.index
    return df.to_dict(orient='records')[ix]
def as_dict ( df , ix = ':' ) : if isinstance ( df . index , pd . DatetimeIndex ) : df [ 'datetime' ] = df . index return df . to_dict ( orient = 'records' ) [ ix ]
converts df to dict and adds a datetime field if df is datetime