<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sample(self, n):
 """Samples data into a Pandas DataFrame. Note that it calls BigQuery so it will incur cost. Args: n: number of sampled counts. Note that the number of counts returned is approximated. Returns: A dataframe containing sampled data. Raises: Exception if n is larger than number of rows. """

    total = bq.Query('select count(*) from %s' %
                     self._get_source()).execute().result()[0].values()[0]
    if n > total:
      raise ValueError('sample larger than population')
    sampling = bq.Sampling.random(percent=n * 100.0 / float(total))
    if self._query is not None:
      source = self._query
    else:
      source = 'SELECT * FROM `%s`' % self._table
    sample = bq.Query(source).execute(sampling=sampling).result()
    df = sample.to_dataframe()
    return df