benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 939223ee-3693-5eb2-bb9b-003cc161f17e

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


def task_func(input_string: str) -> pd.DataFrame:
    """
    Process a multi-line string by replacing tabs with spaces and converting it into a pandas DataFrame.
    Each non-empty line of the input string is transformed into a separate row in the DataFrame.
    The function specifically filters out empty lines and replaces tabs with single spaces in the remaining lines.

    Parameters:
    - input_string (str): A multi-line string. Each line is separated by a newline character ('\\n').

    Returns:
    - pd.DataFrame: A DataFrame with a single column named 'Text'. Each row in this column corresponds to a non-empty
      line from the input string, with tabs replaced by spaces.

    Requirements:
    - re
    - pandas

    Note:
    - The function excludes lines that are empty or contain only whitespace.
    - Tabs within the lines are replaced with a single space. For instance, a '\\t' character in the input string
      will be replaced by ' ' in the output DataFrame.

    Example:
    >>> df = task_func('line a\\nfollowed by line b with a\\ttab\\n\\n...bye\\n')
    >>> print(df.head())
                                Text
    0                         line a
    1  followed by line b with a tab
    2                         ...bye
    """

instruct prompt

Process a multi-line string by replacing tabs with spaces and converting it into a pandas DataFrame. Each non-empty line of the input string is transformed into a separate row in the DataFrame. The function specifically filters out empty lines and replaces tabs with single spaces in the remaining lines.
Note that: The function excludes lines that are empty or contain only whitespace. Tabs within the lines are replaced with a single space. For instance, a '\\t' character in the input string will be replaced by ' ' in the output DataFrame.
The function should output with:
    pd.DataFrame: A DataFrame with a single column named 'Text'. Each row in this column corresponds to a non-empty
    line from the input string, with tabs replaced by spaces.
You should write self-contained code starting with:

Code

import re
import pandas as pd
def task_func(input_string: str) -> pd.DataFrame:

code prompt

Code

import re
import pandas as pd
def task_func(input_string: str) -> pd.DataFrame:

entry point

task_func

libs

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