benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf eff91a01-a0ab-5508-8237-15d4d37c5adb

Problem

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

complete prompt

import numpy as np
import pandas as pd


def task_func(data_str, separator=",", bins=20):
    """
    Convert a string of numerical values separated by a specified separator into a pandas
    numerical series with int64, and then draw a histogram of the data.

    The function raises a ValueError if data is empty or it fails to convert the data.
    It plots the histogram with the following attributes:
    - grid: True
    - rwidth: 0.9
    - color: '#607c8e'

    Parameters:
    - data_str (str): The string of numbers separated by the specified separator.
    - separator (str, optional): The separator used in the data string. Default is ','.
    - bins (int, optional): Number of histogram bins. Default is 20.

    Returns:
    - tuple: A tuple containing:
        1. Series: A pandas Series of the data coonverted into integers.
        2. Axes: The Axes object of the plotted histogram.

    Requirements:
    - numpy
    - pandas

    Example:
    >>> series, ax = task_func('1,2,3,4,5,5,5,4,3,2,1')
    >>> print(type(series), series.tolist())
    <class 'pandas.core.series.Series'> [1, 2, 3, 4, 5, 5, 5, 4, 3, 2, 1]
    >>> print(type(ax))
    <class 'matplotlib.axes._axes.Axes'>
    """

instruct prompt

Convert a string of numerical values separated by a specified separator into a pandas numerical series with int64, and then draw a histogram of the data. The function raises a ValueError if data is empty or it fails to convert the data. It plots the histogram with the following attributes: - grid: True - rwidth: 0.9 - color: '#607c8e'
The function should output with:
    tuple: A tuple containing:
    1. Series: A pandas Series of the data coonverted into integers.
    2. Axes: The Axes object of the plotted histogram.
You should write self-contained code starting with:

Code

import numpy as np
import pandas as pd
def task_func(data_str, separator=",", bins=20):

code prompt

Code

import numpy as np
import pandas as pd
def task_func(data_str, separator=",", bins=20):

entry point

task_func

libs

  • pandas
  • numpy

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