benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf f6d4cb0b-1938-57ae-b513-d6cfd70fb126

Problem

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

complete prompt

import pandas as pd
from random import randint, seed


def task_func(dictionary, item, sample_size=None, random_seed=None):
    """
    Converts a dictionary to a pandas DataFrame and Find the positions of a particular item in a the resulting DataFrame and record its frequency distribution.
    Optionally, return a random sample of these positions, with an option to set a random seed for reproducibility.

    Parameters:
    dictionary (dictionary): The dictionary.
    item (str): The item to find.
    sample_size (int, optional): The number of positions to randomly sample. If None, all positions are returned.
    random_seed (int, optional): The seed for the random number generator. If None, the results are not reproducible.

    Returns:
    list: A list of positions (row index, column name) where the item is found.
    DataFrame: The converted dictionary.

    Requirements:
    - pandas
    - random.seed
    - random.randint

    Example:
    >>> dictionary = ([['Apple', 'Banana', 'Orange', 'Apple', 'Banana'] for _ in range(5)])
    >>> positions = task_func(dictionary, 'Apple', sample_size=2, random_seed=42)
    >>> print(positions)
    ([(0, 3), (0, 0)],        0       1       2      3       4
    0  Apple  Banana  Orange  Apple  Banana
    1  Apple  Banana  Orange  Apple  Banana
    2  Apple  Banana  Orange  Apple  Banana
    3  Apple  Banana  Orange  Apple  Banana
    4  Apple  Banana  Orange  Apple  Banana)

    >>> dictionary =  {
    ...         1: ['road', 'car', 'traffic'],
    ...         2: ['car', 'light', 'candle']
    ...     }
    >>> positions = task_func(dictionary, 'car')
    >>> print(positions)
    ([(0, 2), (1, 1)],          1       2
    0     road     car
    1      car   light
    2  traffic  candle)
    """

instruct prompt

Converts a dictionary to a pandas DataFrame and Find the positions of a particular item in a the resulting DataFrame and record its frequency distribution. Optionally, return a random sample of these positions, with an option to set a random seed for reproducibility. >>> dictionary =  { ...         1: ['road', 'car', 'traffic'], ...         2: ['car', 'light', 'candle'] ...     } >>> positions = task_func(dictionary, 'car') >>> print(positions) ([(0, 2), (1, 1)],          1       2 0     road     car 1      car   light 2  traffic  candle)
The function should output with:
    list: A list of positions (row index, column name) where the item is found.
    DataFrame: The converted dictionary.
You should write self-contained code starting with:

Code

import pandas as pd
from random import randint, seed
def task_func(dictionary, item, sample_size=None, random_seed=None):

code prompt

Code

import pandas as pd
from random import randint, seed
def task_func(dictionary, item, sample_size=None, random_seed=None):

entry point

task_func

libs

  • pandas
  • random

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