benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 18befc38-1a31-52b3-a3d4-748ce1dab7cf

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

# Constants for pie chart colors
COLORS = ['r', 'g', 'b', 'y', 'm']

def task_func(df, col, title=None):
    """
    Draw a pie chart of the number of unique values in a given DataFrame column with an optional title.

    Parameters:
    - df (DataFrame): The input DataFrame containing the data.
    - col (str): The column name for which the pie chart is to be plotted.
    - title (str, optional): The title of the pie chart. If None, no title is set.

    Returns:
    - Axes: A matplotlib axes object representing the pie chart.

    Requirements:
    - pandas
    - matplotlib.pyplot

    Example:
    >>> df = pd.DataFrame({'fruit': ['apple', 'banana', 'orange', 'apple', 'banana', 'banana']})
    >>> ax = task_func(df, 'fruit', title='Fruit Distribution')
    >>> print(ax.get_title())
    Fruit Distribution
    >>> plt.close()

    Raises:
    - The input df must be DataFrame, not be empty, and must contain the specified column, if it is not, the function will raise ValueError.

    Note:
    - Each unique value in the column is represented by a slice in the pie chart with a unique color from a predefined set. 
    - The pie chart can have a title if specified.

    """

instruct prompt

Draw a pie chart of the number of unique values in a given DataFrame column with an optional title.
Note that: Each unique value in the column is represented by a slice in the pie chart with a unique color from a predefined set. The pie chart can have a title if specified.
The function should raise the exception for: The input df must be DataFrame, not be empty, and must contain the specified column, if it is not, the function will raise ValueError.
The function should output with:
    Axes: A matplotlib axes object representing the pie chart.
You should write self-contained code starting with:

Code

import pandas as pd
import matplotlib.pyplot as plt
# Constants for pie chart colors
COLORS = ['r', 'g', 'b', 'y', 'm']
def task_func(df, col, title=None):

code prompt

Code

import pandas as pd
import matplotlib.pyplot as plt
# Constants for pie chart colors
COLORS = ['r', 'g', 'b', 'y', 'm']
def task_func(df, col, title=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