benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf b4189d50-192b-593c-ac5a-7e593056674e

Problem

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

complete prompt

import re
import pandas as pd
import numpy as np
# Constants
DATA_PATTERN = r'>\d+\.\d+<'


def task_func(dataframe, data_pattern=DATA_PATTERN):
    """
    Extract numeric data from a Pandas DataFrame based on a specific pattern. The function searches 
    each cell for occurrences of the regex pattern '>number<number>' (e.g., '>1.23<') and replaces 
    the cell content with the extracted numeric value. If no match is found, the cell is replaced with NaN.
    
    Parameters:
    - dataframe (pd.DataFrame): A pandas DataFrame containing data to be processed.
    - data_pattern (str, optional): data search pattern. Default value is '>\d+\.\d+<'.
    
    Returns:
    - pd.DataFrame: A modified DataFrame with cells containing the extracted numeric values or NaN.
    
    Requirements:
    - re
    - pandas
    - numpy
    
    Example:
    >>> import pandas as pd
    >>> df = pd.DataFrame({'A': ['>1.23<', '>4.56<'], 'B': ['>7.89<', '>0.12<']})
    >>> task_func(df)
          A     B
    0  1.23  7.89
    1  4.56  0.12
    """

instruct prompt

Extract numeric data from a Pandas DataFrame based on a specific pattern. The function searches each cell for occurrences of the regex pattern '>number<number>' (e.g., '>1.23<') and replaces the cell content with the extracted numeric value. If no match is found, the cell is replaced with NaN.
The function should output with:
    pd.DataFrame: A modified DataFrame with cells containing the extracted numeric values or NaN.
You should write self-contained code starting with:

Code

import re
import pandas as pd
import numpy as np
# Constants
DATA_PATTERN = r'>\d+\.\d+<'
def task_func(dataframe, data_pattern=DATA_PATTERN):

code prompt

Code

import re
import pandas as pd
import numpy as np
# Constants
DATA_PATTERN = r'>\d+\.\d+<'
def task_func(dataframe, data_pattern=DATA_PATTERN):

entry point

task_func

libs

  • pandas
  • numpy
  • re

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