benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf ba804448-3170-594c-b02e-2629610c42dc
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import pandas as pd
import os
import numpy as np
import ast
def task_func(directory):
"""
Traverse a directory for CSV files a get the file with the longest filename. From that CSV file, load e-mail data, convert it into a Pandas DataFrame, calculate the sum, mean and median of the list associated with each e-mail, and then draw a histogram of the median.
- The column names of each CSV files are 'email' and 'list'.
- The column 'list' contains a string representation of a list. It should be converted before usage.
- If there is not csv file in the directory, return an empty dataframe with the columns expected.
- If there is not csv file in the directory, return None instead of an empty plot.
Parameters:
- directory (str): The path to the directory.
Returns:
- pandas.DataFrame : DataFrame containing the data from the CSV file with the longest filename augmented with the columns 'sum', 'mean' and 'median'.
- matplotlib.axes._axes.Axes : Histogram of the median. None if there is no data to plot.
Requirements:
- pandas
- os
- numpy
- ast
Example:
>>> task_func('data_directory')
"""
instruct prompt
Traverse a directory for CSV files a get the file with the longest filename. From that CSV file, load e-mail data, convert it into a Pandas DataFrame, calculate the sum, mean and median of the list associated with each e-mail, and then draw a histogram of the median. - The column names of each CSV files are 'email' and 'list'. - The column 'list' contains a string representation of a list. It should be converted before usage. - If there is not csv file in the directory, return an empty dataframe with the columns expected. - If there is not csv file in the directory, return None instead of an empty plot.
The function should output with:
pandas.DataFrame : DataFrame containing the data from the CSV file with the longest filename augmented with the columns 'sum', 'mean' and 'median'.
matplotlib.axes._axes.Axes : Histogram of the median. None if there is no data to plot.
You should write self-contained code starting with:
Code
import pandas as pd
import os
import numpy as np
import ast
def task_func(directory):
code prompt
Code
import pandas as pd
import os
import numpy as np
import ast
def task_func(directory):
entry point
task_func
libs
- pandas
- numpy
- ast
- os
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