benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 9becf3a7-cc2c-5a52-866f-7a6238c45259

Problem

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

complete prompt

import pandas as pd
from scipy.spatial.distance import pdist, squareform


def task_func(array):
    """
    Generate a Pandas DataFrame from a 2D list and calculate a distance matrix.

    This function converts a 2D list into a DataFrame, with columns named alphabetically starting from 'A'.
    It uses the `chr()` function, which converts an integer to its corresponding Unicode character,
    to dynamically assign alphabetical labels to each column based on their index. The function then
    computes the Euclidean distance matrix between rows.

    Parameters:
    array (list of list of int): The 2D list representing the data.
                                 Each sublist must contain only integers or floats. If the input does not
                                 conform to this structure, a TypeError is raised.

    Returns:
    - df (pd.DataFrame): data converted from 2D list.
    - distance_matrix (pd.DataFrame): output distance matrix.

    Requirements:
    - pandas
    - scipy.spatial.distance.pdist
    - scipy.spatial.distance.squareform

    Example:
    >>> df, distance_matrix = task_func([[1,2,3,4,5], [6,7,8,9,10]])
    >>> print(df)
       A  B  C  D   E
    0  1  2  3  4   5
    1  6  7  8  9  10
    >>> print(distance_matrix)
              0         1
    0   0.00000  11.18034
    1  11.18034   0.00000
    """

instruct prompt

Generate a Pandas DataFrame from a 2D list and calculate a distance matrix. This function converts a 2D list into a DataFrame, with columns named alphabetically starting from 'A'. It uses the `chr()` function, which converts an integer to its corresponding Unicode character, to dynamically assign alphabetical labels to each column based on their index. The function then computes the Euclidean distance matrix between rows.
The function should output with:
    df (pd.DataFrame): data converted from 2D list.
    distance_matrix (pd.DataFrame): output distance matrix.
You should write self-contained code starting with:

Code

import pandas as pd
from scipy.spatial.distance import pdist, squareform
def task_func(array):

code prompt

Code

import pandas as pd
from scipy.spatial.distance import pdist, squareform
def task_func(array):

entry point

task_func

libs

  • pandas
  • 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