benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 65705720-76a6-50a7-a5f3-ff641e6c0203
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import pandas as pd
import re
import random
def task_func(s: str, seed: int = 0) -> pd.DataFrame:
"""
Generate a Pandas DataFrame of products with their ID, quantity, code, price, product, and description
based on a specified string of product data.
The input string is expected to be divided into segments by newlines. Each segment is expected to
be further split into parts by whitespace: ID, quantity, code, price, and a product description.
The function will remove trailing whitespaces in each field and assign a product name per unique code.
Product name is randomly sampled from: ['Apple', 'Banana', 'Orange', 'Pear', 'Grape'].
The same product name will be assigned to each code for each input s, however different codes can be
mapped to the same name.
Parameters:
- s (str): Product data string split by newline, then whitespace.
Expected format per segment: '<ID> <Quantity> <Code> <Price> <Description>'
If incomplete, this function raises ValueError.
- seed (int): Random seed for reproducibility. Defaults to 0.
Returns:
- data_df (pd.DataFrame): DataFrame with columns: ['ID', 'Quantity', 'Code', 'Price', 'Product', 'Description'].
Quantity and Price are expected to be integers.
Requirements:
- pandas
- re
- random
Examples:
>>> s = '1 10 A10B 100 This is a description with spaces'
>>> df = task_func(s)
>>> df
ID Quantity Code Price Product Description
0 1 10 A10B 100 Pear This is a description with spaces
>>> s = '1 10 A10B 100 This is a description with spaces\\n2 20 B20C 200 Another description example'
>>> df = task_func(s)
>>> df
ID Quantity Code Price Product Description
0 1 10 A10B 100 Pear This is a description with spaces
1 2 20 B20C 200 Pear Another description example
"""
instruct prompt
Generate a Pandas DataFrame of products with their ID, quantity, code, price, product, and description based on a specified string of product data. The input string is expected to be divided into segments by newlines. Each segment is expected to be further split into parts by whitespace: ID, quantity, code, price, and a product description. The function will remove trailing whitespaces in each field and assign a product name per unique code. Product name is randomly sampled from: ['Apple', 'Banana', 'Orange', 'Pear', 'Grape']. The same product name will be assigned to each code for each input s, however different codes can be mapped to the same name. >>> s = '1 10 A10B 100 This is a description with spaces\\n2 20 B20C 200 Another description example' >>> df = task_func(s) >>> df ID Quantity Code Price Product Description 0 1 10 A10B 100 Pear This is a description with spaces 1 2 20 B20C 200 Pear Another description example
The function should output with:
data_df (pd.DataFrame): DataFrame with columns: ['ID', 'Quantity', 'Code', 'Price', 'Product', 'Description'].
Quantity and Price are expected to be integers.
You should write self-contained code starting with:
Code
import pandas as pd
import re
import random
def task_func(s: str, seed: int = 0) -> pd.DataFrame:
code prompt
Code
import pandas as pd
import re
import random
def task_func(s: str, seed: int = 0) -> pd.DataFrame:
entry point
task_func
libs
- pandas
- random
- re
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