benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 6a412d36-bb71-5224-9d17-ff9515993277

Problem

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

complete prompt

import pandas as pd
import logging

# Set up basic configuration for logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

def task_func(sheet_name, excel_file_location="test.xlsx", csv_file_location="test.csv"):
    """
    Reads data from an Excel spreadsheet, converts it to a CSV file, then calculates the sum of each column in the CSV file.

    Parameters:
    - sheet_name (str): The name of the sheet to load data from.
    - excel_file_location (str): The path to the Excel file. Default is 'test.xlsx'.
    - csv_file_location (str): The path where the CSV file will be saved. Default is 'test.csv'.

    Returns:
    - dict: A dictionary with the sum of each column.

    Raises:
    - FileNotFoundError: If the Excel file does not exist at the specified path.
    - ValueError: If the specified sheet name is not found in the Excel file.

    Requirements:
    - pandas
    - logging

    Example:
    >>> test_excel_file = 'dummy_test.xlsx'
    >>> test_csv_file = 'dummy_test.csv'
    >>> test_sheet_name = 'TestSheet'
    >>> data = {'A': [10, 20, 30], 'B': [40, 50, 60]}
    >>> df = pd.DataFrame(data)
    >>> df.to_excel(test_excel_file, sheet_name=test_sheet_name, index=False)
    >>> task_func(sheet_name='TestSheet', excel_file_location=test_excel_file, csv_file_location=test_csv_file) # {'Column1': sum_value1, 'Column2': sum_value2, ...}
    {'A': 60, 'B': 150}
    >>> os.remove(test_excel_file)
    >>> os.remove(test_csv_file)
    
    Note:
    - Ensure the Excel file contains only numerical data for accurate sum calculations.
    """

instruct prompt

Reads data from an Excel spreadsheet, converts it to a CSV file, then calculates the sum of each column in the CSV file.
Note that: Ensure the Excel file contains only numerical data for accurate sum calculations.
The function should raise the exception for: FileNotFoundError: If the Excel file does not exist at the specified path. ValueError: If the specified sheet name is not found in the Excel file.
The function should output with:
    dict: A dictionary with the sum of each column.
You should write self-contained code starting with:

Code

import pandas as pd
import logging
# Set up basic configuration for logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def task_func(sheet_name, excel_file_location="test.xlsx", csv_file_location="test.csv"):

code prompt

Code

import pandas as pd
import logging
# Set up basic configuration for logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def task_func(sheet_name, excel_file_location="test.xlsx", csv_file_location="test.csv"):

entry point

task_func

libs

  • pandas
  • logging

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