benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf e7500727-8a48-5a1e-a419-f19cd0790c1f

Problem

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

complete prompt

import pandas as pd
from datetime import datetime

def task_func(data, date_format, country, country_codes=None):
    """ 
    Draw a histogram of the data from a DataFrame column of the pandas after converting the data into a specific format,
    and return the matplotlib Axes object.

    Parameters:
    data (DataFrame): The pandas DataFrame containing date strings. The DataFrame has a column named 'dates' with the format '%d/%m/%Y'
    date_format (str): The date format string.
    country (str): The country name.
    country_codes (dict, optional): A dictionary mapping country names. Defaults to a predefined dictionary, where default is:
        default_country_codes = {
            'Russia': 'ru_RU',
            'Germany': 'de_DE',
            'France': 'fr_FR',
            'Spain': 'es_ES',
            'Italy': 'it_IT'
        }

    Returns:
    matplotlib.axes.Axes: The Axes object of the plotted histogram.

    Raises:
    ValueError: If 'data' is not a DataFrame, 'date_format' is not a string, 'country' is not in 'country_codes',
                or 'country_codes' is not a dictionary.

    Additional Notes:
    The title of the plot should be 'Date Distribution'. The y label should be named with 'Frequency'.
    
    Requirements:
    - pandas
    - datetime

    Example:
    >>> data = pd.DataFrame({'dates': ['01/01/2000', '01/02/2000', '02/03/2000', '04/05/2000', '06/07/2000']})
    >>> ax = task_func(data, '%d/%m/%Y', 'Russia')
    >>> ax.get_title()
    'Date Distribution'
    """

instruct prompt

Draw a histogram of the data from a DataFrame column of the pandas after converting the data into a specific format, and return the matplotlib Axes object. Additional Notes: The title of the plot should be 'Date Distribution'. The y label should be named with 'Frequency'.
The function should raise the exception for: ValueError: If 'data' is not a DataFrame, 'date_format' is not a string, 'country' is not in 'country_codes', or 'country_codes' is not a dictionary.
The function should output with:
    matplotlib.axes.Axes: The Axes object of the plotted histogram.
You should write self-contained code starting with:

Code

import pandas as pd
from datetime import datetime
def task_func(data, date_format, country, country_codes=None):

code prompt

Code

import pandas as pd
from datetime import datetime
def task_func(data, date_format, country, country_codes=None):

entry point

task_func

libs

  • pandas
  • datetime

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