benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf a10c9e3d-d5b6-5b4c-98ac-306646b8dda5
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import pandas as pd
import numpy as np
DEFAULT_COLUMNS = ['Element', 'Count']
def task_func(elements, include_index=False):
"""
Constructs a DataFrame that enumerates the character counts of each string in a provided list of elements. This
function can optionally include an index column for each row in the DataFrame.
Parameters:
elements (List[str]): A list of strings whose character counts are to be calculated.
include_index (bool): Flag to decide whether to add an index column in the resulting DataFrame.
Returns: DataFrame: Returns a pandas DataFrame with columns for elements and their respective character counts.
Includes an 'Index' column if requested.
Requirements:
- pandas
- numpy
Note:
The order of columns in the returned DataFrame will be ['Index', 'Element', 'Count'] if the index is included.
Example:
>>> result = task_func(['abc', 'def'], include_index=True)
>>> print(result.to_string(index=False))
Index Element Count
0 abc 3
1 def 3
"""
instruct prompt
Constructs a DataFrame that enumerates the character counts of each string in a provided list of elements. This function can optionally include an index column for each row in the DataFrame.
Note that: The order of columns in the returned DataFrame will be ['Index', 'Element', 'Count'] if the index is included.
The function should output with:
DataFrame: Returns a pandas DataFrame with columns for elements and their respective character counts.
Includes an 'Index' column if requested.
You should write self-contained code starting with:
Code
import pandas as pd
import numpy as np
DEFAULT_COLUMNS = ['Element', 'Count']
def task_func(elements, include_index=False):
code prompt
Code
import pandas as pd
import numpy as np
DEFAULT_COLUMNS = ['Element', 'Count']
def task_func(elements, include_index=False):
entry point
task_func
libs
- pandas
- numpy
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
initial import