benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf cc7fec72-981c-5852-a0e9-f8c54654d55b

Problem

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

complete prompt

import collections
import pandas as pd

def task_func(obj_list, attr):
    """
    Count the frequency of each value of the given attribute from a list of objects.
    
    This function returns a pandas Dataframe containing frequency count of the specified attribute from the objects in the list.
    The DataFrame consist of two columns ('attribute' and 'count'), which contain the attribute and its
    specific count respectively.
    
    If no attributes are found, an empty DataFrame is returned.

    Parameters:
    obj_list (list): The list of objects with attributes.
    attr (str): The attribute to count.

    Returns:
    collections.Counter: The frequency count of each value of the attribute.

    Requirements:
    - collections
    - pandas
    
    Example:
    >>> class ExampleObject:
    ...     def __init__(self, color, shape):
    ...         self.color = color
    ...         self.shape = shape
    ...
    >>> obj_list = [ExampleObject('Red', 'Square'), ExampleObject('Green', 'Circle'), ExampleObject('Red', 'Rectangle')]
    >>> count = task_func(obj_list, 'color')
    >>> print(count)
      attribute  count
    0       Red      2
    1     Green      1


    >>> class ExampleObject:
    ...     def __init__(self, animal, shape):
    ...         self.animal = animal
    ...         self.shape = shape
    ...
    >>> obj_list = [ExampleObject('tiger', 'Square'), ExampleObject('leopard', 'Circle'), ExampleObject('cat', 'Rectangle'), ExampleObject('elephant', 'Rectangle')]
    >>> count = task_func(obj_list, 'shape')
    >>> print(count)
       attribute  count
    0     Square      1
    1     Circle      1
    2  Rectangle      2
    """

instruct prompt

Count the frequency of each value of the given attribute from a list of objects. This function returns a pandas Dataframe containing frequency count of the specified attribute from the objects in the list. The DataFrame consist of two columns ('attribute' and 'count'), which contain the attribute and its specific count respectively. If no attributes are found, an empty DataFrame is returned. >>> class ExampleObject: ...     def __init__(self, animal, shape): ...         self.animal = animal ...         self.shape = shape ... >>> obj_list = [ExampleObject('tiger', 'Square'), ExampleObject('leopard', 'Circle'), ExampleObject('cat', 'Rectangle'), ExampleObject('elephant', 'Rectangle')] >>> count = task_func(obj_list, 'shape') >>> print(count) attribute  count 0     Square      1 1     Circle      1 2  Rectangle      2
The function should output with:
    collections.Counter: The frequency count of each value of the attribute.
You should write self-contained code starting with:

Code

import collections
import pandas as pd
def task_func(obj_list, attr):

code prompt

Code

import collections
import pandas as pd
def task_func(obj_list, attr):

entry point

task_func

libs

  • pandas
  • collections

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