benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf ff70df9a-a6d6-53ff-b280-b0baae5af2b3
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import re
import matplotlib.pyplot as plt
def task_func(df):
"""
Analyzes a DataFrame to find videos with titles containing "how" or "what" and visualizes their like ratios.
The like ratio for each video is calculated by dividing the number of likes by the number of views.
This function generates a bar plot of the like ratios for these specific videos.
If the DataFrame is empty, lacks the required columns, or contains no titles matching the criteria,
an empty subplot is returned.
Parameters:
df (DataFrame): A DataFrame containing video data with columns 'Title', 'Views', and 'Likes'.
Returns:
Axes: A matplotlib.axes.Axes object of the bar plot. The plot will be empty if the DataFrame is insufficient
or no video titles match the search criteria.
Requirements:
- re
- matplotlib
Note:
The function checks for the presence of the necessary data columns ('Title', 'Views', 'Likes') and whether
there are any entries matching the search criteria. If these conditions are not met, it returns an empty plot.
Example:
>>> import pandas as pd
>>> data = {'Title': ['How to code', 'What is Python', 'Tutorial'], 'Views': [1500, 1200, 1000], 'Likes': [150, 300, 100]}
>>> df = pd.DataFrame(data)
>>> ax = task_func(df)
>>> type(ax)
<class 'matplotlib.axes._axes.Axes'>
"""
instruct prompt
Analyzes a DataFrame to find videos with titles containing "how" or "what" and visualizes their like ratios. The like ratio for each video is calculated by dividing the number of likes by the number of views. This function generates a bar plot of the like ratios for these specific videos. If the DataFrame is empty, lacks the required columns, or contains no titles matching the criteria, an empty subplot is returned.
Note that: The function checks for the presence of the necessary data columns ('Title', 'Views', 'Likes') and whether there are any entries matching the search criteria. If these conditions are not met, it returns an empty plot.
The function should output with:
Axes: A matplotlib.axes.Axes object of the bar plot. The plot will be empty if the DataFrame is insufficient
or no video titles match the search criteria.
You should write self-contained code starting with:
Code
import re
import matplotlib.pyplot as plt
def task_func(df):
code prompt
Code
import re
import matplotlib.pyplot as plt
def task_func(df):
entry point
task_func
libs
- matplotlib
- 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