benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 670b3a27-c567-5af3-b221-ad2fac34aa83
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import pandas as pd
import matplotlib.pyplot as plt
# Constants
COLUMN_NAMES = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
def task_func(data):
"""
Computes the average of each row in a provided 2D array and appends these averages as a new column.
Additionally, it plots the averages against their respective row indices.
Parameters:
data (numpy.array): A 2D numpy array with exactly eight columns, corresponding to 'A' through 'H'.
Returns:
tuple: A tuple containing:
- DataFrame: A pandas DataFrame which includes the original data and an additional 'Average' column.
- Axes: A matplotlib Axes object with the plot of row averages.
Requirements:
- pandas
- matplotlib
Example:
>>> import numpy as np
>>> data = np.array([[1, 2, 3, 4, 4, 3, 7, 1], [6, 2, 3, 4, 3, 4, 4, 1]])
>>> df, ax = task_func(data)
>>> print(df.to_string(index=False))
A B C D E F G H Average
1 2 3 4 4 3 7 1 3.125
6 2 3 4 3 4 4 1 3.375
"""
instruct prompt
Computes the average of each row in a provided 2D array and appends these averages as a new column. Additionally, it plots the averages against their respective row indices.
The function should output with:
tuple: A tuple containing:
DataFrame: A pandas DataFrame which includes the original data and an additional 'Average' column.
Axes: A matplotlib Axes object with the plot of row averages.
You should write self-contained code starting with:
Code
import pandas as pd
import matplotlib.pyplot as plt
# Constants
COLUMN_NAMES = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
def task_func(data):
code prompt
Code
import pandas as pd
import matplotlib.pyplot as plt
# Constants
COLUMN_NAMES = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
def task_func(data):
entry point
task_func
libs
- pandas
- matplotlib
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