benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 2bd8423a-b808-5717-ac92-4b07b87aea49

Problem

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

complete prompt

import pandas as pd
from sklearn.preprocessing import StandardScaler

def task_func(df, age, weight):
    """
    Filters and standardizes a given DataFrame based on specified age and weight criteria.

    This function first filters the rows in the input DataFrame where 'Age' is less than the 
    specified 'age' and 'Weight' is greater than the specified 'weight'. It then standardizes 
    the numerical values in the filtered DataFrame using the StandardScaler from sklearn.

    Parameters:
    df (pd.DataFrame): The input DataFrame containing at least the columns 'Age' and 'Weight'.
    age (numeric): The age threshold for filtering rows. Rows with 'Age' less than this value 
                   are selected.
    weight (numeric): The weight threshold for filtering rows. Rows with 'Weight' greater than 
                      this value are selected.

    Returns:
    pd.DataFrame: A DataFrame containing the filtered and standardized data. If the filtering 
                  results in an empty DataFrame, an empty DataFrame is returned.
    
    Raises:
    KeyError: If the input DataFrame does not contain the required columns 'Age' and 'Weight'.
  
    Requirements:
        - sklearn.preprocessing.StandardScaler
        - pandas

    Examples:

    >>> data = pd.DataFrame({
    ...     "Age": [32, 51, 11, 5, 88, 434],
    ...     "Weight": [62, 76, 72, 859, 69, 102],
    ...     "shoe_size": [12, 6, 7, 8, 9, 6]
    ... })
    >>> print(task_func(data, 70, 63))
           Age    Weight  shoe_size
    0  1.40400 -0.701695  -1.224745
    1 -0.55507 -0.712504   0.000000
    2 -0.84893  1.414200   1.224745

    >>> input = pd.DataFrame({
    ...     "Age": [32, 51, 12, 1, 55, 11, 23, 5],
    ...     "Weight": [62, 63, 12, 24, 11, 111, 200, 70],
    ...     "banana_consumption": [1, 1, 7, 2, 100, 6, 26, 1]
    ... })
    >>> print(task_func(input, 32, 22))
            Age    Weight  banana_consumption
    0 -1.083473 -1.192322           -0.666109
    1  0.120386  0.150487           -0.271378
    2  1.565016  1.524165            1.702277
    3 -0.601929 -0.482331           -0.764791
    """

instruct prompt

Filters and standardizes a given DataFrame based on specified age and weight criteria. This function first filters the rows in the input DataFrame where 'Age' is less than the specified 'age' and 'Weight' is greater than the specified 'weight'. It then standardizes the numerical values in the filtered DataFrame using the StandardScaler from sklearn. >>> data = pd.DataFrame({ ...     "Age": [32, 51, 11, 5, 88, 434], ...     "Weight": [62, 76, 72, 859, 69, 102], ...     "shoe_size": [12, 6, 7, 8, 9, 6] ... }) >>> print(task_func(data, 70, 63)) Age    Weight  shoe_size 0  1.40400 -0.701695  -1.224745 1 -0.55507 -0.712504   0.000000 2 -0.84893  1.414200   1.224745 >>> input = pd.DataFrame({ ...     "Age": [32, 51, 12, 1, 55, 11, 23, 5], ...     "Weight": [62, 63, 12, 24, 11, 111, 200, 70], ...     "banana_consumption": [1, 1, 7, 2, 100, 6, 26, 1] ... }) >>> print(task_func(input, 32, 22)) Age    Weight  banana_consumption 0 -1.083473 -1.192322           -0.666109 1  0.120386  0.150487           -0.271378 2  1.565016  1.524165            1.702277 3 -0.601929 -0.482331           -0.764791
The function should raise the exception for: KeyError: If the input DataFrame does not contain the required columns 'Age' and 'Weight'.
The function should output with:
    pd.DataFrame: A DataFrame containing the filtered and standardized data. If the filtering
    results in an empty DataFrame, an empty DataFrame is returned.
You should write self-contained code starting with:

Code

import pandas as pd
from sklearn.preprocessing import StandardScaler
def task_func(df, age, weight):

code prompt

Code

import pandas as pd
from sklearn.preprocessing import StandardScaler
def task_func(df, age, weight):

entry point

task_func

libs

  • pandas
  • sklearn

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