benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 8aef31a2-63a9-5703-a540-f8c4a06d1593

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

def task_func(df, dct, columns=None, plot_histograms=False):
    '''
    Replace values in a DataFrame with a dictionary mapping and optionally record histograms for specified columns.
    
    Parameters:
    df (DataFrame): The input DataFrame.
    dct (dict): A dictionary for replacing values in df.
    columns (list of str, optional): List of column names to plot histograms. If None, no histograms are plotted.
    plot_histograms (bool): If True, plots histograms for specified columns.

    Returns:
    DataFrame: The DataFrame with replaced values. The columns are in the format of 'col1', 'col2', etc.

    Requirements:
    - pandas
    - matplotlib.pyplot
    
    Raises:
    - The function will raise a ValueError is input df is not a DataFrame.
    
    Example:
    >>> df = pd.DataFrame({'col1': [1, 2, 3, 4], 'col2': [5, 6, 7, 8], 'col3': [9, 10, 11, 12]})
    >>> dct = {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 10: 'j', 11: 'k', 12: 'l'}
    >>> modified_df = task_func(df, dct)
    >>> modified_df
      col1 col2 col3
    0    a    e    i
    1    b    f    j
    2    c    g    k
    3    d    h    l
    '''

instruct prompt

Replace values in a DataFrame with a dictionary mapping and optionally record histograms for specified columns.
The function should raise the exception for: The function will raise a ValueError is input df is not a DataFrame.
The function should output with:
    DataFrame: The DataFrame with replaced values. The columns are in the format of 'col1', 'col2', etc.
You should write self-contained code starting with:

Code

import pandas as pd
import matplotlib.pyplot as plt
def task_func(df, dct, columns=None, plot_histograms=False):

code prompt

Code

import pandas as pd
import matplotlib.pyplot as plt
def task_func(df, dct, columns=None, plot_histograms=False):

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