docs: def sample_to(self, count, skip_header_rows, strategy, target):
      """Sample rows from GCS or local file and save results to target file.
  
      Args:
        count: number of rows to sample. If strategy is "BIGQUERY", it is used as approximate number.
        skip_header_rows: whether to skip first row when reading from source.
        strategy: can be "LOCAL" or "BIGQUERY". If local, the sampling happens in local memory,
            and number of resulting rows matches count. If BigQuery, sampling is done
            with BigQuery in cloud, and the number of resulting rows will be approximated to
            count.
        target: The target file path, can be GCS or local path.
      Raises:
        Exception if strategy is "BIGQUERY" but source is not a GCS path.
      """
      # TODO(qimingj) Add unit test
      # Read data from source into DataFrame.
  
      if sys.version_info.major > 2:
        xrange = range  # for python 3 compatibility
  
      if strategy == 'BIGQUERY':
        import datalab.bigquery as bq
        if not self.path.startswith('gs://'):
          raise Exception('Cannot use BIGQUERY if data is not in GCS')
        federated_table = self._create_federated_table(skip_header_rows)
        row_count = self._get_gcs_csv_row_count(federated_table)
        query = bq.Query('SELECT * from data', data_sources={'data': federated_table})
        sampling = bq.Sampling.random(count * 100 / float(row_count))
        sample = query.sample(sampling=sampling)
        df = sample.to_dataframe()
      elif strategy == 'LOCAL':
        local_file = self.path
        if self.path.startswith('gs://'):
          local_file = tempfile.mktemp()
          datalab.utils.gcs_copy_file(self.path, local_file)
        with open(local_file) as f:
          row_count = sum(1 for line in f)
        start_row = 1 if skip_header_rows is True else 0
        skip_count = row_count - count - 1 if skip_header_rows is True else row_count - count
        skip = sorted(random.sample(xrange(start_row, row_count), skip_count))
        header_row = 0 if skip_header_rows is True else None
        df = pd.read_csv(local_file, skiprows=skip, header=header_row, delimiter=self._delimiter)
        if self.path.startswith('gs://'):
          os.remove(local_file)
      else:
        raise Exception('strategy must be BIGQUERY or LOCAL')
      # Write to target.
      if target.startswith('gs://'):
        with tempfile.NamedTemporaryFile() as f:
          df.to_csv(f, header=False, index=False)
          f.flush()
          datalab.utils.gcs_copy_file(f.name, target)
      else:
        with open(target, 'w') as f:
          df.to_csv(f, header=False, index=False, sep=str(self._delimiter))