benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf a1a1c822-df52-5584-9e5f-c9f7ab5cc1dd
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
from sklearn.feature_extraction.text import TfidfVectorizer
import numpy as np
def task_func(df):
"""
Analyzes a given DataFrame containing article titles and content to identify articles with titles that include
the words "how" or "what". It calculates the TF-IDF scores for the words in the content of these articles and
visualizes these scores in a bar plot.
Parameters:
df (DataFrame): A DataFrame containing at least two columns: 'Title' and 'Content'.
Returns:
Axes: A matplotlib Axes object displaying a bar plot of the TF-IDF scores.
Note:
- If the DataFrame does not contain 'Title' and 'Content' columns, the function returns an empty plot.
- If no articles have titles containing "how" or "what," the function also returns an empty plot.
- Set the name of the y-axis to 'TF-IDF Score'.
- Set xticks to display the feature names vertically.
Requirements:
- re
- matplotlib
- sklearn
- numpy
Example:
>>> import pandas as pd
>>> data = {'Title': ['How to make pancakes', 'News update'], 'Content': ['Pancakes are easy to make.', 'Today’s news is about politics.']}
>>> df = pd.DataFrame(data)
>>> ax = task_func(df)
>>> type(ax)
<class 'matplotlib.axes._axes.Axes'>
"""
instruct prompt
Analyzes a given DataFrame containing article titles and content to identify articles with titles that include the words "how" or "what". It calculates the TF-IDF scores for the words in the content of these articles and visualizes these scores in a bar plot.
Note that: If the DataFrame does not contain 'Title' and 'Content' columns, the function returns an empty plot. If no articles have titles containing "how" or "what," the function also returns an empty plot. Set the name of the y-axis to 'TF-IDF Score'. Set xticks to display the feature names vertically.
The function should output with:
Axes: A matplotlib Axes object displaying a bar plot of the TF-IDF scores.
You should write self-contained code starting with:
Code
import re
import matplotlib.pyplot as plt
from sklearn.feature_extraction.text import TfidfVectorizer
import numpy as np
def task_func(df):
code prompt
Code
import re
import matplotlib.pyplot as plt
from sklearn.feature_extraction.text import TfidfVectorizer
import numpy as np
def task_func(df):
entry point
task_func
libs
- numpy
- matplotlib
- re
- sklearn
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