benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf b5bbb1ed-5a08-5de7-8935-095aef9aa3d4

Problem

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

complete prompt

import pickle
import os


def task_func(df, file_name="save.pkl"):
    """
    Save the provided Pandas DataFrame "df" in a pickle file with the given name, read it
    back for validation, and delete the intermediate file.

    Parameters:
    df (DataFrame): The pandas DataFrame to be saved.
    file_name (str, optional): Name of the file where the DataFrame will be saved. Defaults to 'save.pkl'.

    Returns:
    loaded_df (pd.DataFrame): The loaded DataFrame from the specified file.

    Requirements:
    - pickle
    - os

    Example:
    >>> import pandas as pd
    >>> import numpy as np
    >>> np.random.seed(0)
    >>> df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
    >>> loaded_df = task_func(df, 'test_file.pkl')
    >>> assert df.equals(loaded_df)
    >>> type(df), type(loaded_df)
    (<class 'pandas.core.frame.DataFrame'>, <class 'pandas.core.frame.DataFrame'>)
    >>> df.head(2)
        A   B   C   D
    0  44  47  64  67
    1  67   9  83  21
    """

instruct prompt

Save the provided Pandas DataFrame "df" in a pickle file with the given name, read it back for validation, and delete the intermediate file.
The function should output with:
    loaded_df (pd.DataFrame): The loaded DataFrame from the specified file.
You should write self-contained code starting with:

Code

import pickle
import os
def task_func(df, file_name="save.pkl"):

code prompt

Code

import pickle
import os
def task_func(df, file_name="save.pkl"):

entry point

task_func

libs

  • pickle
  • os

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