Extract measured data from `FeedbackResults` instance into
    `pandas.DataFrame`.
4974
def feedback_results_to_measurements_frame(feedback_result):
    '''
    
    '''
    index = pd.Index(feedback_result.time * 1e-3, name='seconds')
    df_feedback = pd.DataFrame(np.column_stack([feedback_result.V_fb,
                                                feedback_result.V_hv,
                                                feedback_result.fb_resistor,
                                                feedback_result.hv_resistor]),
                               columns=['V_fb', 'V_hv', 'fb_resistor',
                                        'hv_resistor'],
                               index=index)
    df_feedback.insert(0, 'frequency', feedback_result.frequency)
    return df_feedback
562212
def get_observed_strains_and_df(observation, observation_dict):
    
    observed_df = pd.DataFrame.from_records(observation_dict[observation], columns=['strain','phenotype']).set_index('strain')
    observed_strains = observed_df.index.tolist()
    return observed_strains, observed_df
270946
def serialize(data, measurement=None, tag_columns=None, **extra_tags):
    """"""
    if isinstance(data, bytes):
        return data
    elif isinstance(data, str):
        return data.encode('utf-8')
    elif hasattr(data, 'to_lineprotocol'):
        return data.to_lineprotocol()
    elif pd is not None and isinstance(data, pd.DataFrame):
        return dataframe.serialize(data, measurement, tag_columns, **extra_tags)
    elif isinstance(data, dict):
        return mapping.serialize(data, measurement, **extra_tags)
    elif hasattr(data, '__iter__'):
        return b'\n'.join([serialize(i, measurement, tag_columns, **extra_tags) for i in data])
    else:
        raise ValueError('Invalid input', data)
572938
def make_dataframe(result):
    
    import pandas as pd
    ret = {}
    if isinstance(result,dict):
        if 'timeseries' in result:
            result = result['timeseries']
    for uuid, data in result.items():
        df = pd.DataFrame(data)
        if len(df.columns) == 5: # statistical data
            df.columns = ['time','min','mean','max','count']
        else:
            df.columns = ['time','value']
        df['time'] = pd.to_datetime(df['time'],unit='ns')
        df = df.set_index(df.pop('time'))
        ret[uuid] = df
    return ret
928929
def _data(self, copy=False):
        
        data = {}
        for key, obj in self.__dict__.items():
            if isinstance(obj, (pd.Series, pd.DataFrame, pd.SparseSeries, pd.SparseDataFrame)):
                if copy:
                    data[key] = obj.copy()
                else:
                    data[key] = obj
        return data
625162
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'interval' in _dict:
            args['interval'] = _dict.get('interval')
        if 'event_type' in _dict:
            args['event_type'] = _dict.get('event_type')
        if 'results' in _dict:
            args['results'] = [
                MetricAggregationResult._from_dict(x)
                for x in (_dict.get('results'))
            ]
        return cls(**args)
998112
def _return_samples(return_type, samples):
    
    if return_type.lower() == "dataframe":
        if HAS_PANDAS:
            return pandas.DataFrame.from_records(samples)
        else:
            warn("Pandas installation not found. Returning numpy.recarray object")
            return samples
    else:
        return samples
105868
def to_pandas(self, columns=None):
        # pylint: disable=import-error
        
        import pandas
        return pandas.DataFrame.from_records(self.to_list(), columns=columns)
1000538
def process_prediction_results(results, show_image):
  """"""

  import pandas as pd

  if (is_in_IPython() and show_image is True):
    import IPython
    for image_url, image, label_and_score in results:
      IPython.display.display_html('<p style="font-size:28px">%s(%.5f)</p>' % label_and_score,
                                   raw=True)
      IPython.display.display(IPython.display.Image(data=image))
  result_dict = [{'image_url': url, 'label': r[0], 'score': r[1]} for url, _, r in results]
  return pd.DataFrame(result_dict)
475129
def getJsonData(self, params):
        
        try:
            return eval("self." + str(params['output_id']) + "(params)")
        except AttributeError:
            df = self.getData(params)
            if df is None:
                return None
            return df.to_dict(orient='records')
668537
def multidim_measurement_to_attachment(name, measurement):
  """"""

  dimensions = list(measurement.dimensions)
  if measurement.units:
    dimensions.append(
        measurements.Dimension.from_unit_descriptor(measurement.units))

  dims = []
  for d in dimensions:
    if d.suffix is None:
      suffix = u''
    # Ensure that the suffix is unicode. It's typically str/bytes because
    # units.py looks them up against str/bytes.
    elif isinstance(d.suffix, unicode):
      suffix = d.suffix
    else:
      suffix = d.suffix.decode('utf8')
    dims.append({
        'uom_suffix': suffix,
        'uom_code': d.code,
        'name': d.name,
    })
  # Refer to the module docstring for the expected schema.
  dimensioned_measured_value = measurement.measured_value
  value = (sorted(dimensioned_measured_value.value, key=lambda x: x[0])
           if dimensioned_measured_value.is_value_set else None)
  outcome_str = MEASUREMENT_OUTCOME_TO_TEST_RUN_STATUS_NAME[measurement.outcome]
  data = _convert_object_to_json({
      'outcome': outcome_str,
      'name': name,
      'dimensions': dims,
      'value': value,
  })
  attachment = htf_test_record.Attachment(data, test_runs_pb2.MULTIDIM_JSON)

  return attachment
688925
def _get_processed_dataframe(self, dataframe):
        
        dataframe.index = pd.to_datetime(dataframe['epoch'], unit='s', utc=True)
        del dataframe['epoch']
        summary = dataframe.describe(percentiles=[.80, .90, .95]).transpose().loc['scriptrun_time']
        df_grp = dataframe.groupby(pd.TimeGrouper('{}S'.format(self.interval)))
        df_final = df_grp.apply(lambda x: x.describe(percentiles=[.80, .90, .95])['scriptrun_time'])

        return {
            "raw": dataframe.round(2),
            "compiled": df_final.round(2),
            "summary": summary.round(2)
        }
1038590
def to_df(self)->None:
        ""
        return pd.DataFrame(dict(x=self.x._relative_item_paths(), y=[str(o) for o in self.y]))
433744
def data(cls, cube, weighted, prune):
        """"""
        return cls()._data(cube, weighted, prune)
611353
def process(self):
        
        # Short cut
        if self._all_expressions_evaluated():
            if self.drop:
                # Drop extra columns. They do not correspond to
                # any expressions.
                columns = [expr.column for expr in self.expressions]
                self.data = self.data.loc[:, columns]
            return self.data

        # group_by
        # evaluate expressions
        # combine columns
        # concat evalutated group data and clean up index and group
        gdfs = self._get_group_dataframes()
        egdfs = self._evaluate_expressions(gdfs)
        edata = self._concat(egdfs)
        return edata
621110
def get_result(self):
        

        # dispatch to agg
        if is_list_like(self.f) or is_dict_like(self.f):
            return self.obj.aggregate(self.f, axis=self.axis,
                                      *self.args, **self.kwds)

        # all empty
        if len(self.columns) == 0 and len(self.index) == 0:
            return self.apply_empty_result()

        # string dispatch
        if isinstance(self.f, str):
            # Support for `frame.transform('method')`
            # Some methods (shift, etc.) require the axis argument, others
            # don't, so inspect and insert if necessary.
            func = getattr(self.obj, self.f)
            sig = inspect.getfullargspec(func)
            if 'axis' in sig.args:
                self.kwds['axis'] = self.axis
            return func(*self.args, **self.kwds)

        # ufunc
        elif isinstance(self.f, np.ufunc):
            with np.errstate(all='ignore'):
                results = self.obj._data.apply('apply', func=self.f)
            return self.obj._constructor(data=results, index=self.index,
                                         columns=self.columns, copy=False)

        # broadcasting
        if self.result_type == 'broadcast':
            return self.apply_broadcast()

        # one axis empty
        elif not all(self.obj.shape):
            return self.apply_empty_result()

        # raw
        elif self.raw and not self.obj._is_mixed_type:
            return self.apply_raw()

        return self.apply_standard()
610137
def to_dataframe(self):
    

    data = []
    for target_index, target_row in enumerate(self._cm):
      for predicted_index, count in enumerate(target_row):
        data.append((self._labels[target_index], self._labels[predicted_index], count))

    return pd.DataFrame(data, columns=['target', 'predicted', 'count'])