benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 852b4b6c-89e8-5fda-8b07-7b05c596bf60

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(data, column_name="target_column"):
    """
    Converts a given JSON data into a Pandas DataFrame and plots a histogram of a specified column.
    The function handles non-numeric columns by converting them to categorical type and then to numeric codes. 
    It also checks if the specified column exists in the DataFrame.

    - The histogram's title is set to 'Histogram of <column_name>'.
    - The histogram's x-label are set to the name of the specified column.
    
    Parameters:
    - data (list of dict)
    - column_name (str, optional)

    Returns:
    - DataFrame: A pandas DataFrame created from the input JSON data.
    - Axes: A matplotlib Axes object showing the histogram plot of the specified column.

    Exceptions:
    - ValueError: Raised if the specified column name does not exist in the DataFrame.

    Requirements:
    - pandas
    - matplotlib

    Example:
    >>> sample_data = [{'userId': 1, 'value': 10}, {'userId': 2, 'value': 15}]
    >>> df, ax = task_func(sample_data, 'userId')
    >>> print(df)
       userId  value
    0       1     10
    1       2     15
    """

instruct prompt

Converts a given JSON data into a Pandas DataFrame and plots a histogram of a specified column. The function handles non-numeric columns by converting them to categorical type and then to numeric codes. It also checks if the specified column exists in the DataFrame. - The histogram's title is set to 'Histogram of <column_name>'. - The histogram's x-label are set to the name of the specified column. Exceptions: - ValueError: Raised if the specified column name does not exist in the DataFrame.
The function should output with:
    DataFrame: A pandas DataFrame created from the input JSON data.
    Axes: A matplotlib Axes object showing the histogram plot of the specified column.
You should write self-contained code starting with:

Code

import pandas as pd
import matplotlib.pyplot as plt
def task_func(data, column_name="target_column"):

code prompt

Code

import pandas as pd
import matplotlib.pyplot as plt
def task_func(data, column_name="target_column"):

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