benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 60e458c7-313d-524a-a614-d31f21a7018d

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
import seaborn as sns

# Constants
PLOT_TITLE = "Value Distribution"


def task_func(data_dict):
    """
    Processes a dictionary of numerical data to create a pandas DataFrame, removes None values, and generates a histogram 
    of the data values using seaborn. The histogram's bins are dynamically calculated based on the range of the data. Specifically,
    the number of bins is set to the minimum of 11 and half the number of data points, with a minimum of 2 bins.
    If the DataFrame is empty or the data lacks variability (all values are the same after removing None values), 
    the function does not generate a plot.

    Parameters:
    - data_dict (dict): A dictionary with keys as column names and values as lists of numerical data. 
                      The data can include None values, which will be removed.

    Returns:
    - DataFrame: A pandas DataFrame created from the input dictionary, excluding None values.
    - Axes or None: A seaborn histogram plot object if the DataFrame contains variable data; 
                               None if the DataFrame is empty or if all values are identical.

    Requirements:
    - pandas
    - numpy
    - seaborn

    Note:
    - Calculates the minimum and maximum values in the DataFrame.
    - Dynamically sets the number of bins for the histogram based on the number of data points, with a minimum of 2 
         and a maximum of 11 bins.
    - Create evenly spaced bin edges between the minimum and maximum values.
    - KDE (Kernel Density Estimate) is turned off. 
    - Sets the plot title to the predefined constant `PLOT_TITLE`.


    Example:
    >>> data = {'a': [1, 2, 3, None], 'b': [5, 6, None, 8]}
    >>> df, plot = task_func(data)
    >>> df
         a    b
    0  1.0  5.0
    1  2.0  6.0
    >>> plot.get_title() if plot is not None else 'No plot generated'
    'Value Distribution'
    """

instruct prompt

Processes a dictionary of numerical data to create a pandas DataFrame, removes None values, and generates a histogram of the data values using seaborn. The histogram's bins are dynamically calculated based on the range of the data. Specifically, the number of bins is set to the minimum of 11 and half the number of data points, with a minimum of 2 bins. If the DataFrame is empty or the data lacks variability (all values are the same after removing None values), the function does not generate a plot.
Note that: Calculates the minimum and maximum values in the DataFrame. Dynamically sets the number of bins for the histogram based on the number of data points, with a minimum of 2 and a maximum of 11 bins. Create evenly spaced bin edges between the minimum and maximum values. KDE (Kernel Density Estimate) is turned off. Sets the plot title to the predefined constant `PLOT_TITLE`.
The function should output with:
    DataFrame: A pandas DataFrame created from the input dictionary, excluding None values.
    Axes or None: A seaborn histogram plot object if the DataFrame contains variable data;
    None if the DataFrame is empty or if all values are identical.
You should write self-contained code starting with:

Code

import numpy as np
import pandas as pd
import seaborn as sns
# Constants
PLOT_TITLE = "Value Distribution"
def task_func(data_dict):

code prompt

Code

import numpy as np
import pandas as pd
import seaborn as sns
# Constants
PLOT_TITLE = "Value Distribution"
def task_func(data_dict):

entry point

task_func

libs

  • pandas
  • numpy
  • seaborn

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