benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf a053e316-19b4-57f7-9ea5-b852f186d9fa

Problem

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

complete prompt

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

TARGET_VALUES = np.array([1, 3, 4])

def task_func(df):
    """
    Replace all elements in DataFrame columns that do not exist in the TARGET_VALUES array with zeros, then perform a Box-Cox transformation on each column (if data is not constant, add 1 to account for zeros) and display the resulting KDE plots.

    Parameters:
        - df (pandas.DataFrame): The input pandas DataFrame with positive values.

    Returns:
        - pandas.DataFrame: The transformed DataFrame after Box-Cox transformation.
        - matplotlib.figure.Figure: Figure containing KDE plots of the transformed columns.

    Requirements:
    - numpy
    - scipy.stats
    - matplotlib.pyplot

    Example:
    >>> np.random.seed(42)
    >>> df = pd.DataFrame(np.random.randint(1, 10, size=(100, 5)), columns=list('ABCDE'))  # Values should be positive for Box-Cox
    >>> transformed_df, fig = task_func(df)
    >>> print(transformed_df.head(2))
              A         B    C    D         E
    0  0.000000  0.566735  0.0  0.0  0.000000
    1  0.530493  0.000000  0.0  0.0  0.607007
    """

instruct prompt

Replace all elements in DataFrame columns that do not exist in the TARGET_VALUES array with zeros, then perform a Box-Cox transformation on each column (if data is not constant, add 1 to account for zeros) and display the resulting KDE plots.
The function should output with:
    pandas.DataFrame: The transformed DataFrame after Box-Cox transformation.
    matplotlib.figure.Figure: Figure containing KDE plots of the transformed columns.
You should write self-contained code starting with:

Code

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
TARGET_VALUES = np.array([1, 3, 4])
def task_func(df):

code prompt

Code

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
TARGET_VALUES = np.array([1, 3, 4])
def task_func(df):

entry point

task_func

libs

  • numpy
  • matplotlib
  • scipy

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