def as_dict ( df , ix = ':' ) : if isinstance ( df . index , pd . DatetimeIndex ) : df [ 'datetime' ] = df . index return df . to_dict ( orient = 'records' ) [ ix ]
create python dictionary based on data frame value and index
converts df to dict and adds a datetime field if df is datetime
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]