benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 3c3d02bb-ec39-54ae-83f2-10560aad329c

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder

def task_func(num_samples, countries=['Russia', 'China', 'USA', 'India', 'Brazil'], 
           ages=np.arange(18, 60), genders=['Male', 'Female'], rng_seed=None):
    """
    Generate a demographic dataset with information about people from different countries, their age, and gender. 
    Genders are encoded using sklearn LabelEncoder.
    Datapoints are sampled from the lists using a numpy.random.default_rng with seed: rng_seed.

    Parameters:
    num_samples (int): The number of samples to generate.
    countries (list of str): A list of country names to use in the dataset. Default is ['Russia', 'China', 'USA', 'India', 'Brazil'].
    ages (array of int): An array of ages to use in the dataset. Default is np.arange(18, 60).
    genders (list of str): A list of genders to use in the dataset. Default is ['Male', 'Female'].
    rng_seed: seed for the random number generator
    
    Returns:
    DataFrame: A pandas DataFrame with the demographics data.

    Raises:
    - ValueError: If num_samples is not an integer.

    Requirements:
    - pandas
    - numpy
    - sklearn.preprocessing.LabelEncoder

    Example:
    >>> demographics = task_func(5, rng_seed=31)
    >>> print(demographics)
      Country  Age  Gender
    0     USA   46       0
    1  Brazil   21       1
    2     USA   37       1
    3  Russia   32       1
    4     USA   46       0

    >>> demographics = task_func(5, countries=['Austria', 'Germany'], rng_seed=3)
    >>> print(demographics)
       Country  Age  Gender
    0  Germany   51       1
    1  Austria   54       1
    2  Austria   42       0
    3  Austria   19       1
    4  Austria   21       1
    """

instruct prompt

Generate a demographic dataset with information about people from different countries, their age, and gender. Genders are encoded using sklearn LabelEncoder. Datapoints are sampled from the lists using a numpy.random.default_rng with seed: rng_seed. >>> demographics = task_func(5, countries=['Austria', 'Germany'], rng_seed=3) >>> print(demographics) Country  Age  Gender 0  Germany   51       1 1  Austria   54       1 2  Austria   42       0 3  Austria   19       1 4  Austria   21       1
The function should raise the exception for: ValueError: If num_samples is not an integer.
The function should output with:
    DataFrame: A pandas DataFrame with the demographics data.
You should write self-contained code starting with:

Code

import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
def task_func(num_samples, countries=['Russia', 'China', 'USA', 'India', 'Brazil'], 
           ages=np.arange(18, 60), genders=['Male', 'Female'], rng_seed=None):

code prompt

Code

import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
def task_func(num_samples, countries=['Russia', 'China', 'USA', 'India', 'Brazil'], 
           ages=np.arange(18, 60), genders=['Male', 'Female'], rng_seed=None):

entry point

task_func

libs

  • pandas
  • numpy
  • sklearn

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import