benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 0a649d71-a231-5627-a7a9-bddfb70fe151

Problem

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

complete prompt

import pandas as pd
import matplotlib.pyplot as plt

def task_func(df, items=None, locations=None):
    """
    Generates a bar chart representing the distribution of specified items across given locations.
    
    The function takes a DataFrame with 'Item' and 'Location' columns and plots the count of each item
    per location. If lists of items and locations are provided, the chart will only include those specified,
    otherwise it defaults to a predefined list.

    Parameters:
    - df (pandas.DataFrame): DataFrame containing 'Item' and 'Location' columns.
    - items (list of str, optional): Specific items to include in the chart. Defaults to a predefined list
      ['apple', 'banana', 'grape', 'orange', 'pineapple'] if None.
    - locations (list of str, optional): Specific locations to include in the chart. Defaults to a predefined
      list ['store1', 'store2', 'store3', 'store4', 'store5'] if None.

    Returns:
    - matplotlib.axes.Axes: Axes object with the plotted bar chart.

    Raises:
    - ValueError: If 'df' is not a DataFrame, or if 'Item' or 'Location' columns are missing.

    Requirements:
    - pandas
    - matplotlib.pyplot

    Example:
    >>> df = pd.DataFrame({
    ...     'Item': ['apple', 'banana', 'apple', 'orange'],
    ...     'Location': ['store1', 'store2', 'store3', 'store1']
    ... })
    >>> ax = task_func(df)
    >>> ax.get_title()
    'Item Distribution by Location'
    """

instruct prompt

Generates a bar chart representing the distribution of specified items across given locations. The function takes a DataFrame with 'Item' and 'Location' columns and plots the count of each item per location. If lists of items and locations are provided, the chart will only include those specified, otherwise it defaults to a predefined list.
The function should raise the exception for: ValueError: If 'df' is not a DataFrame, or if 'Item' or 'Location' columns are missing.
The function should output with:
    matplotlib.axes.Axes: Axes object with the plotted bar chart.
You should write self-contained code starting with:

Code

import pandas as pd
import matplotlib.pyplot as plt
def task_func(df, items=None, locations=None):

code prompt

Code

import pandas as pd
import matplotlib.pyplot as plt
def task_func(df, items=None, locations=None):

entry point

task_func

libs

  • pandas
  • matplotlib

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