def trace_to_dataframe(trace, chains=None, varnames=None, hide_transformed_vars=True):
 var_shapes = trace._straces[0].var_shapes
 if (varnames is None):
  varnames = var_shapes.keys()
 flat_names = {v: create_flat_names(v, shape) for (v, shape) in var_shapes.items() if (not (hide_transformed_vars and v.endswith('_')))}
 var_dfs = []
 for (v, shape) in var_shapes.items():
  if (v in varnames):
   if ((not hide_transformed_vars) or (not v.endswith('_'))):
    vals = trace.get_values(v, combine=True, chains=chains)
    flat_vals = vals.reshape(vals.shape[0], (-1))
    var_dfs.append(pd.DataFrame(flat_vals, columns=flat_names[v]))
 return pd.concat(var_dfs, axis=1)

def trace_to_dataframe ( trace , chains = None , varnames = None , hide_transformed_vars = True ) : var_shapes = trace . _straces [ 0 ] . var_shapes if ( varnames is None ) : varnames = var_shapes . keys ( ) flat_names = { v : create_flat_names ( v , shape ) for ( v , shape ) in var_shapes . items ( ) if ( not ( hide_transformed_vars and v . endswith ( '_' ) ) ) } var_dfs = [ ] for ( v , shape ) in var_shapes . items ( ) : if ( v in varnames ) : if ( ( not hide_transformed_vars ) or ( not v . endswith ( '_' ) ) ) : vals = trace . get_values ( v , combine = True , chains = chains ) flat_vals = vals . reshape ( vals . shape [ 0 ] , ( - 1 ) ) var_dfs . append ( pd . DataFrame ( flat_vals , columns = flat_names [ v ] ) ) return pd . concat ( var_dfs , axis = 1 )
convert trace to pandas dataframe .